aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gm/atlastext.cpp13
-rw-r--r--include/atlastext/SkAtlasTextTarget.h4
-rw-r--r--src/atlastext/SkAtlasTextTarget.cpp11
-rw-r--r--tools/SkTestScalerContext.cpp4
4 files changed, 21 insertions, 11 deletions
diff --git a/gm/atlastext.cpp b/gm/atlastext.cpp
index a25bb875b3..8270306e5e 100644
--- a/gm/atlastext.cpp
+++ b/gm/atlastext.cpp
@@ -15,6 +15,7 @@
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkTypeface.h"
+#include "SkUtils.h"
#include "gpu/TestContext.h"
#include "gpu/atlastext/GLTestAtlasTextRenderer.h"
#include "gpu/atlastext/TestAtlasTextRenderer.h"
@@ -24,10 +25,18 @@
static SkScalar draw_string(SkAtlasTextTarget* target, const SkString& text, SkScalar x, SkScalar y,
uint32_t color, sk_sp<SkTypeface> typeface, float size) {
- auto font = SkAtlasTextFont::Make(std::move(typeface), size);
- target->drawText(text.c_str(), text.size(), x, y, color, *font);
+ auto font = SkAtlasTextFont::Make(typeface, size);
+ int cnt = SkUTF8_CountUnichars(text.c_str());
+ std::unique_ptr<SkGlyphID[]> glyphs(new SkGlyphID[cnt]);
+ typeface->charsToGlyphs(text.c_str(), SkTypeface::Encoding::kUTF8_Encoding, glyphs.get(), cnt);
+
+ target->drawText(glyphs.get(), cnt, x, y, color, *font);
+
+ // Using a paint just to perform a measure to let the caller know how much space to skip in x.
SkPaint paint;
paint.setTextSize(size);
+ paint.setTypeface(std::move(typeface));
+ paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
return x + paint.measureText(text.c_str(), text.size());
}
diff --git a/include/atlastext/SkAtlasTextTarget.h b/include/atlastext/SkAtlasTextTarget.h
index 0859afde39..a9d5dd5dca 100644
--- a/include/atlastext/SkAtlasTextTarget.h
+++ b/include/atlastext/SkAtlasTextTarget.h
@@ -31,8 +31,8 @@ public:
* Enqueues a text draw in the target. The meaning of 'color' here is interpreted by the
* client's SkAtlasTextRenderer when it actually renders the text.
*/
- virtual void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
- uint32_t color, const SkAtlasTextFont& font) = 0;
+ virtual void drawText(const SkGlyphID*, int glyphCnt, SkScalar x, SkScalar y, uint32_t color,
+ const SkAtlasTextFont& font) = 0;
/** Issues all queued text draws to SkAtlasTextRenderer. */
virtual void flush() = 0;
diff --git a/src/atlastext/SkAtlasTextTarget.cpp b/src/atlastext/SkAtlasTextTarget.cpp
index 57ece37b4f..fa756fe327 100644
--- a/src/atlastext/SkAtlasTextTarget.cpp
+++ b/src/atlastext/SkAtlasTextTarget.cpp
@@ -50,7 +50,7 @@ public:
/** SkAtlasTextTarget overrides */
- void drawText(const void* text, size_t byteLength, SkScalar x, SkScalar y, uint32_t color,
+ void drawText(const SkGlyphID*, int glyphCnt, SkScalar x, SkScalar y, uint32_t color,
const SkAtlasTextFont&) override;
void flush() override;
@@ -78,16 +78,14 @@ std::unique_ptr<SkAtlasTextTarget> SkAtlasTextTarget::Make(sk_sp<SkAtlasTextCont
#include "GrContextPriv.h"
#include "GrDrawingManager.h"
-void SkInternalAtlasTextTarget::drawText(const void* text, size_t byteLength, SkScalar x,
+void SkInternalAtlasTextTarget::drawText(const SkGlyphID* glyphs, int glyphCnt, SkScalar x,
SkScalar y, uint32_t color, const SkAtlasTextFont& font) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setTypeface(font.refTypeface());
paint.setTextSize(font.size());
paint.setStyle(SkPaint::kFill_Style);
-
- // TODO: Figure out what if anything to do with these:
- // Paint setTextEncoding? Font isEnableByteCodeHints()? Font isUseNonLinearMetrics()?
+ paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
// The atlas text context does munging of the paint color. We store the client's color here
// and the context will write it into the final vertices given to the client's renderer.
@@ -98,8 +96,9 @@ void SkInternalAtlasTextTarget::drawText(const void* text, size_t byteLength, Sk
auto* grContext = this->context()->internal().grContext();
auto bounds = SkIRect::MakeWH(fWidth, fHeight);
auto atlasTextContext = grContext->contextPriv().drawingManager()->getAtlasTextContext();
+ size_t byteLength = sizeof(SkGlyphID) * glyphCnt;
atlasTextContext->drawText(grContext, this, GrNoClip(), paint, SkMatrix::I(), props,
- (const char*)text, byteLength, x, y, bounds);
+ (const char*)glyphs, byteLength, x, y, bounds);
}
void SkInternalAtlasTextTarget::addDrawOp(const GrClip& clip, std::unique_ptr<GrAtlasTextOp> op) {
diff --git a/tools/SkTestScalerContext.cpp b/tools/SkTestScalerContext.cpp
index 7797ebfa20..f74b1bd57a 100644
--- a/tools/SkTestScalerContext.cpp
+++ b/tools/SkTestScalerContext.cpp
@@ -151,7 +151,9 @@ int SkTestTypeface::onCharsToGlyphs(const void* chars, Encoding encoding,
case kUTF16_Encoding: ch = SkUTF16_NextUnichar(&utf16); break;
case kUTF32_Encoding: ch = *utf32++; break;
}
- glyphs[i] = fTestFont->codeToIndex(ch);
+ if (glyphs) {
+ glyphs[i] = fTestFont->codeToIndex(ch);
+ }
}
return glyphCount;
}