skbug_5321.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright 2016 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "gm/gm.h"
  8. #include "include/core/SkCanvas.h"
  9. #include "include/core/SkFont.h"
  10. #include "include/core/SkFontTypes.h"
  11. #include "include/core/SkPaint.h"
  12. #include "include/core/SkScalar.h"
  13. #include "include/core/SkTextBlob.h"
  14. #include <string.h>
  15. // https://bugs.skia.org/5321
  16. // two strings should draw the same. PDF did not.
  17. DEF_SIMPLE_GM(skbug_5321, canvas, 128, 128) {
  18. SkFont font;
  19. font.setEdging(SkFont::Edging::kAlias);
  20. font.setSize(30);
  21. const char text[] = "x\314\200y"; // utf8(u"x\u0300y")
  22. SkScalar x = 20, y = 45;
  23. size_t byteLength = strlen(text);
  24. canvas->drawSimpleText(text, byteLength, SkTextEncoding::kUTF8, x, y, font, SkPaint());
  25. y += font.getMetrics(nullptr);
  26. int glyph_count = font.countText(text, byteLength, SkTextEncoding::kUTF8);
  27. SkTextBlobBuilder builder;
  28. auto rec = builder.allocRunPosH(font, glyph_count, y);
  29. font.textToGlyphs(text, byteLength, SkTextEncoding::kUTF8, rec.glyphs, glyph_count);
  30. font.getWidths(rec.glyphs, glyph_count, rec.pos);
  31. for (int i = 0; i < glyph_count; ++i) {
  32. SkScalar w = rec.pos[i];
  33. rec.pos[i] = x;
  34. x += w;
  35. }
  36. canvas->drawTextBlob(builder.make(), 0, 0, SkPaint());
  37. }