Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(318)

Unified Diff: third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.cpp

Issue 1980913002: Unify glyph metrics to use the same Skia API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed a spurious header line Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.cpp
diff --git a/third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.cpp b/third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..05e92c252823f69f8e7659a66ea51207e071b696
--- /dev/null
+++ b/third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.cpp
@@ -0,0 +1,88 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "SkiaTextMetrics.h"
+
+#include "wtf/MathExtras.h"
+
+#include <SkPath.h>
+
+namespace blink {
+
+static hb_position_t SkiaScalarToHarfBuzzPosition(SkScalar value)
+{
+ // We treat HarfBuzz hb_position_t as 16.16 fixed-point.
+ static const int kHbPosition1 = 1 << 16;
+ return clampTo<int>(value * kHbPosition1);
+}
+
+SkiaTextMetrics::SkiaTextMetrics(const SkPaint* paint)
+ : m_paint(paint)
+{
+ CHECK(m_paint->getTextEncoding() == SkPaint::kGlyphID_TextEncoding);
+}
+
+void SkiaTextMetrics::getGlyphWidthAndExtentsForHarfBuzz(hb_codepoint_t codepoint, hb_position_t* width, hb_glyph_extents_t* extents)
+{
+ DCHECK_LE(codepoint, 0xFFFFu);
+
+ SkScalar skWidth;
+ SkRect skBounds;
+ uint16_t glyph = codepoint;
+
+ m_paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, &skBounds);
+ if (width) {
+ if (!m_paint->isSubpixelText())
+ skWidth = SkScalarRoundToInt(skWidth);
+ *width = SkiaScalarToHarfBuzzPosition(skWidth);
+ }
+ if (extents) {
+ if (!m_paint->isSubpixelText()) {
+ // Use roundOut() rather than round() to avoid rendering glyphs
+ // outside the visual overflow rect. crbug.com/452914.
+ SkIRect ir;
+ skBounds.roundOut(&ir);
+ skBounds.set(ir);
+ }
+ // Invert y-axis because Skia is y-grows-down but we set up HarfBuzz to be y-grows-up.
+ extents->x_bearing = SkiaScalarToHarfBuzzPosition(skBounds.fLeft);
+ extents->y_bearing = SkiaScalarToHarfBuzzPosition(-skBounds.fTop);
+ extents->width = SkiaScalarToHarfBuzzPosition(skBounds.width());
+ extents->height = SkiaScalarToHarfBuzzPosition(-skBounds.height());
+ }
+}
+
+void SkiaTextMetrics::getSkiaBoundsForGlyph(Glyph glyph, SkRect *bounds)
+{
+#if OS(MACOSX)
+ // TODO(drott): Remove this once we have better metrics bounds
+ // on Mac, https://bugs.chromium.org/p/skia/issues/detail?id=5328
+ SkPath path;
+ m_paint->getTextPath(&glyph, sizeof(glyph), 0, 0, &path);
+ *bounds = path.getBounds();
+#else
+ m_paint->getTextWidths(&glyph, sizeof(glyph), nullptr, bounds);
+#endif
+
+ if (!m_paint->isSubpixelText()) {
+ SkIRect ir;
+ bounds->roundOut(&ir);
+ bounds->set(ir);
+ }
+
+}
+
+float SkiaTextMetrics::getSkiaWidthForGlyph(Glyph glyph)
+{
+ SkScalar skWidth;
+ m_paint->getTextWidths(&glyph, sizeof(glyph), &skWidth, nullptr);
+
+ if (!m_paint->isSubpixelText())
+ skWidth = SkScalarRoundToInt(skWidth);
+
+ return SkScalarToFloat(skWidth);
+}
+
+
+} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/fonts/skia/SkiaTextMetrics.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698