/usr/include/Wt/WPdfImage is in libwt-dev 3.3.3+dfsg-4.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | // This may look like C code, but it's really -*- C++ -*-
/*
* Copyright (C) 2010 Emweb bvba, Kessel-Lo, Belgium.
*
* See the LICENSE file for terms of use.
*/
#ifndef WPDF_IMAGE_H_
#define WPDF_IMAGE_H_
#include <Wt/WFont>
#include <Wt/WPaintDevice>
#include <Wt/WResource>
#ifdef WT_TARGET_JAVA
#include <Wt/WTransform>
#endif //WT_TARGET_JAVA
#include <hpdf.h>
namespace Wt {
class FontSupport;
class WTransform;
/*! \class WPdfImage Wt/WPdfImage Wt/WPdfImage
* \brief A paint device for rendering to a PDF.
*
* A %WPdfImage paint device should be used in conjunction with a
* WPainter, and can be used to make a PDF version of a
* WPaintedWidget's contents.
*
* The PDF is generated using <a href="http://libharu.org/">The Haru
* Free PDF Library</a>, and this class is included in the library
* only if <tt>libharu</tt> was found during the build of the library.
*
* You can use the image as a resource and specialize handleRequest()
* to paint the contents on the fly. Alternatively can also use
* write() to serialize to a PDF file (std::ostream). The latter usage
* is illustrated by the code below:
*
* \code Wt::Chart::WCartesianChart
* *chart = ...
*
* Wt::WPdfImage pdfImage("4cm", "3cm");
* {
* Wt::WPainter p(&pdfImage);
* chart->paint(p);
* }
* std::ofstream f("chart.pdf", std::ios::out | std::ios::binary);
* pdfImage.write(f);
* \endcode
*
* A constructor is provided which allows the generated PDF image to
* be embedded directly into a page of a larger <tt>libharu</tt>
* document, and this approach is used for example by the WPdfRenderer
* to render XHTML to multi-page PDF files.
*
* Font information is embedded in the PDF. Fonts supported are native
* PostScript fonts (Base-14) (only ASCII-7), or true type fonts
* (Unicode). See addFontCollection() for more information on how
* fonts are located and matched to WFont descriptions.
*
* This paint device has the following limitations:
* - images (WPainter::drawImage()) can only be included from local
* files, and only JPG and PNG images are supported.
* - drop shadows are not supported.
*
* \ingroup painting
*/
class WT_API WPdfImage : public WResource, public WPaintDevice
{
public:
/*! \brief Create a PDF resource that represents a single-page PDF document.
*
* The single page will have a size \p width x \p height. The PDF
* will be using the same DPI (72dpi) as is conventionally used for
* the desktop.
*
* The passed width and height (such as 4 cm by 3 cm) can be specified in
* physical units (e.g. 4cm x 3cm), but this will be converted to pixels using
* the default DPI used in CSS (96dpi) !
*
* \sa write()
*/
WPdfImage(const WLength& width, const WLength& height, WObject *parent = 0);
/*! \brief Create a PDF paint device to paint inside an existing page.
*
* The image will be drawn in the existing page, as an image with lower-left
* point (\p x, \p y) and size (\p width x \p height).
*/
WPdfImage(HPDF_Doc pdf, HPDF_Page page,
HPDF_REAL x, HPDF_REAL y, HPDF_REAL width, HPDF_REAL height,
WObject *parent = 0);
/*! \brief Destructor.
*/
~WPdfImage();
/*! \brief Adds a font collection.
*
* If %Wt has been configured to use <tt>libpango</tt>, then font
* matching and character selection is done by libpango, which is
* seeded with information on installed fonts by fontconfig. In that
* case, invocations for this method is ignored. Only TrueType fonts
* are supported, and thus you need to configure fontconfig (which
* is used by pango) to only return TrueType fonts. This can be
* done using a fonts.conf configuration %file:
*
* \htmlonly
* <pre>
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<selectfont>
<rejectfont>
<glob>*.pfb</glob>
</rejectfont>
</selectfont>
</fontconfig>
* </pre>
* \endhtmlonly
* You may need to add more glob patterns to exclude other fonts
* than TrueType, and also to exclude TrueType fonts which do not
* work properly with libharu.
*
* If %Wt has not been configured to use <tt>libpango</tt>, then
* this method may be used to indicate the location of TrueType
* fonts. The main drawback compared to libpango is that font
* selection is not steered by the need for particular characters,
* i.e. font selection is independent from the text's need for
* specific characters. Most TrueType fonts provided only partial
* unicode support. The provided \p directory will be searched for
* fonts (currently only TrueType ".ttf" or ".ttc" fonts). TrueType
* fonts are preferable over Base-14 fonts (which are PDF's default
* fonts) since they provide partial (or complete) unicode support.
*
* When using Base-14 fonts, WString::narrow() will be called on text
* which may result in loss of information.
*/
void addFontCollection(const std::string& directory, bool recursive=true);
#ifdef WT_TARGET_JAVA
void setDeviceTransform(const WTransform& deviceTransform);
#endif //WT_TARGET_JAVA
virtual WFlags<WPaintDevice::FeatureFlag> features() const;
virtual void setChanged(WFlags<ChangeFlag> flags);
virtual void drawArc(const WRectF& rect, double startAngle, double spanAngle);
virtual void drawImage(const WRectF& rect, const std::string& imgUri,
int imgWidth, int imgHeight, const WRectF& sourceRect);
virtual void drawLine(double x1, double y1, double x2, double y2);
virtual void drawPath(const WPainterPath& path);
virtual void drawText(const WRectF& rect,
WFlags<AlignmentFlag> alignmentFlags, TextFlag textFlag,
const WString& text);
virtual WTextItem measureText(const WString& text, double maxWidth = -1,
bool wordWrap = false);
virtual WFontMetrics fontMetrics();
virtual void init();
virtual void done();
virtual bool paintActive() const { return painter_ != 0; }
virtual WLength width() const { return width_; }
virtual WLength height() const { return height_; }
void errorHandler(HPDF_STATUS error_no, HPDF_STATUS detail_no);
virtual void handleRequest(const Http::Request& request,
Http::Response& response);
protected:
virtual WPainter *painter() const { return painter_; }
virtual void setPainter(WPainter *painter) { painter_ = painter; }
private:
WLength width_, height_;
WPainter *painter_;
FontSupport *trueTypeFonts_;
HPDF_Doc pdf_;
HPDF_Page page_;
HPDF_Font font_;
bool trueTypeFont_;
std::map<std::string, const char *> ttfFonts_;
WFont currentFont_;
bool myPdf_;
double x_, y_;
double fontSize_;
void paintPath();
void drawPlainPath(const WPainterPath& path);
void applyTransform(const WTransform& f);
};
}
#endif // WPDF_IMAGE_H_
|