aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/xps
diff options
context:
space:
mode:
Diffstat (limited to 'src/xps')
-rw-r--r--src/xps/SkXPSDevice.cpp57
-rw-r--r--src/xps/SkXPSDevice.h2
2 files changed, 59 insertions, 0 deletions
diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp
index ef5f48881d..29ee8f3eca 100644
--- a/src/xps/SkXPSDevice.cpp
+++ b/src/xps/SkXPSDevice.cpp
@@ -2047,6 +2047,63 @@ private:
GlyphRun* const fXpsGlyphs;
};
+void SkXPSDevice::drawText(const void* text, size_t byteLen,
+ SkScalar x, SkScalar y,
+ const SkPaint& paint) {
+ if (byteLen < 1) return;
+
+ if (text_must_be_pathed(paint, this->ctm())) {
+ SkPath path;
+ paint.getTextPath(text, byteLen, x, y, &path);
+ this->drawPath(path, paint, nullptr, true);
+ //TODO: add automation "text"
+ return;
+ }
+
+ TypefaceUse* typeface;
+ HRV(CreateTypefaceUse(paint, &typeface));
+
+ auto cache =
+ SkStrikeCache::FindOrCreateStrikeExclusive(
+ paint, &this->surfaceProps(),
+ SkScalerContextFlags::kNone, nullptr);
+
+ // Advance width and offsets for glyphs measured in hundredths of the font em size
+ // (XPS Spec 5.1.3).
+ FLOAT centemPerUnit = 100.0f / SkScalarToFLOAT(paint.getTextSize());
+ GlyphRun xpsGlyphs;
+ xpsGlyphs.setReserve(num_glyph_guess(paint.getTextEncoding(),
+ static_cast<const char*>(text), byteLen));
+
+ ProcessOneGlyph processOneGlyph(centemPerUnit, typeface->glyphsUsed, &xpsGlyphs);
+
+ SkFindAndPlaceGlyph::ProcessText(
+ paint.getTextEncoding(), static_cast<const char*>(text), byteLen,
+ SkPoint{ x, y }, SkMatrix::I(), paint.getTextAlign(), cache.get(), processOneGlyph);
+
+ if (xpsGlyphs.count() == 0) {
+ return;
+ }
+
+ XPS_POINT origin = {
+ xpsGlyphs[0].horizontalOffset / centemPerUnit,
+ xpsGlyphs[0].verticalOffset / -centemPerUnit,
+ };
+ xpsGlyphs[0].horizontalOffset = 0.0f;
+ xpsGlyphs[0].verticalOffset = 0.0f;
+
+ HRV(AddGlyphs(this->fXpsFactory.get(),
+ this->fCurrentXpsCanvas.get(),
+ typeface,
+ nullptr,
+ xpsGlyphs.begin(), xpsGlyphs.count(),
+ &origin,
+ SkScalarToFLOAT(paint.getTextSize()),
+ XPS_STYLE_SIMULATION_NONE,
+ this->ctm(),
+ paint));
+}
+
void SkXPSDevice::drawPosText(const void* text, size_t byteLen,
const SkScalar pos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& paint) {
diff --git a/src/xps/SkXPSDevice.h b/src/xps/SkXPSDevice.h
index 81e881ea82..a5ee07634c 100644
--- a/src/xps/SkXPSDevice.h
+++ b/src/xps/SkXPSDevice.h
@@ -97,6 +97,8 @@ protected:
const SkRect* srcOrNull, const SkRect& dst,
const SkPaint& paint,
SkCanvas::SrcRectConstraint) override;
+ void drawText(const void* text, size_t len,
+ SkScalar x, SkScalar y, const SkPaint& paint) override;
void drawPosText(const void* text, size_t len,
const SkScalar pos[], int scalarsPerPos,
const SkPoint& offset, const SkPaint& paint) override;