Skip to content

Commit 9c73276

Browse files
committed
Several PDF rendering related fixes:
- Fixed automatic TrueType font selection in WPdfImage with Pango - Added missing fromUTF8
1 parent 479d0cd commit 9c73276

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/Wt/Render/Block.C

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1098,7 +1098,7 @@ double Block::layoutInline(Line& line, BlockList& floats,
10981098
if (item.nextWidth() < 0) {
10991099
for (unsigned i = utf8Pos; i <= s.length(); ++i) {
11001100
if (i == s.length() || isWhitespace(s[i])) {
1101-
WString word = s.substr(utf8Pos, i - utf8Pos);
1101+
WString word = WString::fromUTF8(s.substr(utf8Pos, i - utf8Pos));
11021102
double wordWidth = device->measureText(word).width();
11031103

11041104
w = wordWidth;

src/Wt/WPdfImage

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ private:
183183
bool trueTypeFont_;
184184
std::map<std::string, const char *> ttfFonts_;
185185
WFont currentFont_;
186+
std::string currentTtfFont_;
186187

187188
bool myPdf_;
188189
double x_, y_;

src/Wt/WPdfImage.C

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,25 +254,21 @@ void WPdfImage::setChanged(WFlags<ChangeFlag> flags)
254254
if (flags & Font) {
255255
const WFont& font = painter()->font();
256256

257-
if (font == currentFont_)
257+
if (font == currentFont_ && !trueTypeFonts_->busy())
258258
return;
259259

260260
currentFont_ = font;
261261

262-
const char *font_name = 0;
263-
264-
font_ = 0;
265-
266262
/*
267263
* First, try a true type font.
268264
*/
269265
std::string ttfFont;
270-
if (trueTypeFonts_->busy())
266+
if (trueTypeFonts_->busy()) {
271267
/*
272268
* We have a resolved true type font.
273269
*/
274270
ttfFont = trueTypeFonts_->drawingFontPath();
275-
else {
271+
} else {
276272
FontSupport::FontMatch match = trueTypeFonts_->matchFont(font);
277273

278274
if (match.matched())
@@ -281,7 +277,14 @@ void WPdfImage::setChanged(WFlags<ChangeFlag> flags)
281277

282278
LOG_DEBUG("font: " << ttfFont);
283279

280+
if (!ttfFont.empty() && currentTtfFont_ == ttfFont)
281+
return;
282+
283+
const char *font_name = 0;
284+
font_ = 0;
285+
284286
if (!ttfFont.empty()) {
287+
285288
bool fontOk = false;
286289

287290
std::map<std::string, const char *>::const_iterator i
@@ -321,12 +324,15 @@ void WPdfImage::setChanged(WFlags<ChangeFlag> flags)
321324

322325
if (!font_)
323326
HPDF_ResetError (pdf_);
324-
else
327+
else {
325328
trueTypeFont_ = true;
329+
currentTtfFont_ = ttfFont;
330+
}
326331
}
327332

328333
if (!font_) {
329334
trueTypeFont_ = false;
335+
currentTtfFont_.clear();
330336

331337
std::string name = Pdf::toBase14Font(font);
332338
font_ = HPDF_GetFont(pdf_, name.c_str(), 0);

0 commit comments

Comments
 (0)