aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-05 16:47:59 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-06 12:10:50 +0000
commit3223e276c994c08ecc72d6925851f17e2d9c4732 (patch)
treeee7cd46a6c3a9678472650ddce5663c4f4711941 /src/pdf
parentb1de5f9f2737159ce055305d87d237be5b0dc010 (diff)
SkTypeface: fix non-determinism on AdvacedMetrics
Calculate fStemV and fCapHeight using SkPaint in SkPDFFont if needed. Change-Id: Iaf762e6c44178fac659dfe9fa312d0caed9138ae Reviewed-on: https://skia-review.googlesource.com/21535 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFFont.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/pdf/SkPDFFont.cpp b/src/pdf/SkPDFFont.cpp
index f94dba7080..8fd833e716 100644
--- a/src/pdf/SkPDFFont.cpp
+++ b/src/pdf/SkPDFFont.cpp
@@ -156,6 +156,34 @@ const SkAdvancedTypefaceMetrics* SkPDFFont::GetMetrics(SkTypeface* typeface,
if (!metrics) {
metrics = skstd::make_unique<SkAdvancedTypefaceMetrics>();
}
+
+ if (0 == metrics->fStemV || 0 == metrics->fCapHeight) {
+ SkPaint tmpPaint;
+ tmpPaint.setHinting(SkPaint::kNo_Hinting);
+ tmpPaint.setTypeface(sk_ref_sp(typeface));
+ tmpPaint.setTextSize(1000); // glyph coordinate system
+ if (0 == metrics->fStemV) {
+ // Figure out a good guess for StemV - Min width of i, I, !, 1.
+ // This probably isn't very good with an italic font.
+ int16_t stemV = SHRT_MAX;
+ for (char c : {'i', 'I', '!', '1'}) {
+ SkRect bounds;
+ tmpPaint.measureText(&c, 1, &bounds);
+ stemV = SkTMin(stemV, SkToS16(SkScalarRoundToInt(bounds.width())));
+ }
+ metrics->fStemV = stemV;
+ }
+ if (0 == metrics->fCapHeight) {
+ // Figure out a good guess for CapHeight: average the height of M and X.
+ SkScalar capHeight = 0;
+ for (char c : {'M', 'X'}) {
+ SkRect bounds;
+ tmpPaint.measureText(&c, 1, &bounds);
+ capHeight += bounds.height();
+ }
+ metrics->fCapHeight = SkToS16(SkScalarRoundToInt(capHeight / 2));
+ }
+ }
return canon->fTypefaceMetrics.set(id, std::move(metrics))->get();
}