summaryrefslogtreecommitdiffstats
path: root/pdf
diff options
context:
space:
mode:
authorthestig <thestig@chromium.org>2015-05-20 14:04:33 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-20 21:04:37 +0000
commitd295587a5a0407e0c916e8a9fca62f7b1c38748b (patch)
treeedb1bd97d3eb42a189be73a540cfd0fb6866b068 /pdf
parent4717933ac94bf62a680bc8e77d66e43b35b70dec (diff)
downloadchromium_src-d295587a5a0407e0c916e8a9fca62f7b1c38748b.zip
chromium_src-d295587a5a0407e0c916e8a9fca62f7b1c38748b.tar.gz
chromium_src-d295587a5a0407e0c916e8a9fca62f7b1c38748b.tar.bz2
PDF: On Linux, convert font names to UTF-8 if needed.
BUG=419410 Review URL: https://codereview.chromium.org/1142313002 Cr-Commit-Position: refs/heads/master@{#330801}
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdfium/pdfium_engine.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/pdf/pdfium/pdfium_engine.cc b/pdf/pdfium/pdfium_engine.cc
index f4df4a9..f9feec8 100644
--- a/pdf/pdfium/pdfium_engine.cc
+++ b/pdf/pdfium/pdfium_engine.cc
@@ -6,6 +6,8 @@
#include <math.h>
+#include "base/i18n/icu_encoding_detection.h"
+#include "base/i18n/icu_string_conversions.h"
#include "base/json/json_writer.h"
#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
@@ -223,10 +225,22 @@ void* MapFont(struct _FPDF_SYSFONTINFO*, int weight, int italic,
}
if (i == arraysize(PDFFontSubstitutions)) {
- // TODO(kochi): Pass the face in UTF-8. If face is not encoded in UTF-8,
- // convert to UTF-8 before passing.
- description.set_face(face);
+ // Convert to UTF-8 before calling set_face().
+ std::string face_utf8;
+ if (base::IsStringUTF8(face)) {
+ face_utf8 = face;
+ } else {
+ std::string encoding;
+ if (base::DetectEncoding(face, &encoding)) {
+ // ConvertToUtf8AndNormalize() clears |face_utf8| on failure.
+ base::ConvertToUtf8AndNormalize(face, encoding, &face_utf8);
+ }
+ }
+
+ if (face_utf8.empty())
+ return nullptr;
+ description.set_face(face_utf8);
description.set_weight(WeightToBrowserFontTrustedWeight(weight));
description.set_italic(italic > 0);
}