blob: ef89b63e0448c8b4f5a78cc241d85f2e17a01a6e [file] [log] [blame]
Cary Clarkcb6bef02018-11-29 12:05:25 -05001#Topic Font
2#Alias Font_Reference ##
3
Cary Clark3e73dcf2018-12-06 08:41:14 -05004#Code
5#Populate
6##
7
8#PhraseDef font_metrics
9Typeface, Font_Size, Font_Scale_X,
10Font_Skew_X, Font_Hinting, Paint_Anti_Alias, Font_Embolden, Font_Force_Hinting,
11Font_Embedded_Bitmaps, Font_Hinting_Spacing, Font_Anti_Alias, Font_Linear,
12and Font_Subpixel
13##
14
Cary Clarkcb6bef02018-11-29 12:05:25 -050015#Subtopic Advance
16# incomplete, should probably be in overview, not reference
17##
18#Subtopic Engine
19# incomplete, should probably be in overview, not reference
20##
21
Cary Clark3e73dcf2018-12-06 08:41:14 -050022#Subtopic Size
23#Line # overall height in points ##
24Font_Size adjusts the overall text size in points.
25Font_Size can be set to any positive value or zero.
26Font_Size defaults to 12.
27Font_Size
28##
29
30#Subtopic Scale_X
31#Line # text horizontal scale ##
32Font_Scale_X adjusts the text horizontal scale.
33Text scaling approximates condensed and expanded type faces when the actual face
34is not available.
35Font_Scale_X can be set to any value.
36Font_Scale_X defaults to 1.
37##
38
39#Subtopic Skew_X
40#Line # text horizontal slant ##
41Font_Skew_X adjusts the text horizontal slant.
42Text skewing approximates italic and oblique type faces when the actual face
43is not available.
44Font_Skew_X can be set to any value.
45Font_Skew_X defaults to 0.
46##
47
48#Subtopic Embolden
49#Line # approximate font styles ##
50
51Font_Embolden approximates the bold font style accompanying a normal font when a bold font face
52is not available. Skia does not provide font substitution; it is up to the client to find the
53bold font face using the platform Font_Manager.
54
55Use Font_Skew_X to approximate an italic font style when the italic font face
56is not available.
57
58A FreeType based port may define SK_USE_FREETYPE_EMBOLDEN at compile time to direct
59the font engine to create the bold Glyphs. Otherwise, the extra bold is computed
60by increasing the stroke width and setting the SkPaint::Style to
61SkPaint::kStrokeAndFill_Style as needed.
62
63Font_Embolden is disabled by default.
64#Subtopic Embolden ##
65
66#Subtopic Hinting_Spacing
67#Line # glyph spacing affected by hinting ##
68
69If Hinting is set to SkFontHinting::kFull, Hinting_Spacing adjusts the character
70spacing by the difference of the hinted and unhinted Left_Side_Bearing and
71Right_Side_Bearing. Hinting_Spacing only applies to platforms that use
72FreeType as their Font_Engine.
73
74Hinting_Spacing is not related to text kerning, where the space between
75a specific pair of characters is adjusted using data in the font kerning tables.
76#Subtopic Hinting_Spacing ##
77
78#Subtopic Linear
79#Line # selects text rendering as Glyph or Path ##
80Font_Linear selects whether text is rendered as a Glyph or as a Path.
81If Font_Linear is set, it has the same effect as setting Hinting to SkFontHinting::kNormal.
82If Font_Linear is clear, it is the same as setting Hinting to SkFontHinting::kNone.
83#Subtopic Linear ##
84
85#Subtopic Subpixel
86#Line # uses pixel transparency to represent fractional offset ##
87#Substitute sub-pixel
88Font_Subpixel uses the pixel transparency to represent a fractional offset.
89As the opaqueness of the color increases, the edge of the glyph appears to move
90towards the outside of the pixel.
91#Subtopic Subpixel ##
92
93#Subtopic Anti_Alias
94#Line # text relying on the order of RGB stripes ##
95When set, Anti_Alias positions glyphs within a pixel, using alpha and
96possibly RGB striping. It can take advantage of the organization of RGB stripes
97that create a color, and relies on the small size of the stripe and visual perception
98to make the color fringing imperceptible.
99
100Anti_Alias can be enabled on devices that orient stripes horizontally
101or vertically, and that order the color components as RGB or BGR. Internally, the
102glyph cache may store multiple copies of the same glyph with different sub-pixel
103positions, requiring more memory.
104#Subtopic Anti_Alias ##
105
106#Subtopic Force_Hinting
107#Line # always adjust glyph paths ##
108
109If Hinting is set to SkFontHinting::kNormal or SkFontHinting::kFull, Force_Hinting
110instructs the Font_Manager to always hint Glyphs.
111Force_Hinting has no effect if Hinting is set to SkFontHinting::kNone or
112SkFontHinting::kSlight.
113
114Force_Hinting only affects platforms that use FreeType as the Font_Manager.
115#Subtopic Force_Hinting ##
116
117#Subtopic Embedded_Bitmaps
118#Line # custom sized bitmap Glyphs ##
119Embedded_Bitmaps allows selecting custom sized bitmap Glyphs.
120Embedded_Bitmaps when set chooses an embedded bitmap glyph over an outline contained
121in a font if the platform supports this option.
122
123FreeType selects the bitmap glyph if available when Embedded_Bitmaps is set, and selects
124the outline glyph if Embedded_Bitmaps is clear.
125Windows may select the bitmap glyph but is not required to do so.
126OS_X and iOS do not support this option.
Cary Clarkcb6bef02018-11-29 12:05:25 -0500127##
128
129# ------------------------------------------------------------------------------
130
131#Class SkFont
132
133SkFont controls options applied when drawing and measuring text.
134
135#Code
136#Populate
137##
138
139# ------------------------------------------------------------------------------
140
141#EnumClass Edging
142
143#Code
144#Populate
145##
146
147Whether edge pixels draw opaque or with partial transparency.
148
149#Const kAlias 0 # incomplete; replace '0' with member value
150#Line # no transparent pixels on glyph edges ##
151# incomplete; add description or delete
152##
153#Const kAntiAlias 0 # incomplete; replace '0' with member value
154#Line # may have transparent pixels on glyph edges ##
155# incomplete; add description or delete
156##
157#Const kSubpixelAntiAlias 0 # incomplete; replace '0' with member value
158#Line # glyph positioned in pixel using transparency ##
159# incomplete; add description or delete
160##
161
162# incomplete; add description or delete
163
164#Example
165// incomplete
166##
167
168#SeeAlso incomplete
169
170#EnumClass ##
171
172# ------------------------------------------------------------------------------
173
Cary Clarkcb6bef02018-11-29 12:05:25 -0500174#Method SkFont()
175#In Constructor
176#Line # incomplete ##
177
178#Populate
179
180#Example
181// incomplete
182##
183
184#SeeAlso incomplete
185
186#Method ##
187
188# ------------------------------------------------------------------------------
189
190#Method SkFont(sk_sp<SkTypeface> typeface, SkScalar size)
191#In Constructor
192#Line # incomplete ##
193
194#Populate
195
196#Example
197// incomplete
198##
199
200#SeeAlso incomplete
201
202#Method ##
203
204# ------------------------------------------------------------------------------
205
Cary Clark26d173f2019-01-07 15:16:56 -0500206#Method explicit SkFont(sk_sp<SkTypeface> typeface)
207#In Constructor
208#Line # incomplete ##
209#Populate
210#Example
211// incomplete
212##
213
214#SeeAlso incomplete
215
216#Method ##
217
218# ------------------------------------------------------------------------------
219
Cary Clarkcb6bef02018-11-29 12:05:25 -0500220#Method SkFont(sk_sp<SkTypeface> typeface, SkScalar size, SkScalar scaleX, SkScalar skewX)
221#In Constructor
222#Line # incomplete ##
223
224#Populate
225
226#Example
227// incomplete
228##
229
230#SeeAlso incomplete
231
232#Method ##
233
234# ------------------------------------------------------------------------------
235
Mike Reed42af4922018-11-30 08:54:46 -0500236#Method bool operator==(const SkFont& font) const
237#In Operator
238#Line # compares fonts for equality ##
239
240#Populate
241
242#Example
243// incomplete
244##
245
246#SeeAlso incomplete
247
248#Method ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500249
250# ------------------------------------------------------------------------------
251
Cary Clark26d173f2019-01-07 15:16:56 -0500252#Method bool operator!=(const SkFont& font) const
253#In Operator
254#Line # compares fonts for inequality ##
255
256#Populate
257
258#Example
259// incomplete
260##
261
262#SeeAlso incomplete
263
264#Method ##
265
266# ------------------------------------------------------------------------------
267
Cary Clarkcb6bef02018-11-29 12:05:25 -0500268#Method bool isForceAutoHinting() const
269#In incomplete
270#Line # incomplete ##
271
272#Populate
273
274#Example
275// incomplete
276##
277
278#SeeAlso incomplete
279
280#Method ##
281
282# ------------------------------------------------------------------------------
283
284#Method bool isEmbeddedBitmaps() const
285#In incomplete
286#Line # incomplete ##
287
288#Populate
289
290#Example
291// incomplete
292##
293
294#SeeAlso incomplete
295
296#Method ##
297
298# ------------------------------------------------------------------------------
299
300#Method bool isSubpixel() const
301#In incomplete
302#Line # incomplete ##
303
304#Populate
305
306#Example
307// incomplete
308##
309
310#SeeAlso incomplete
311
312#Method ##
313
314# ------------------------------------------------------------------------------
315
316#Method bool isLinearMetrics() const
317#In incomplete
318#Line # incomplete ##
319
320#Populate
321
322#Example
323// incomplete
324##
325
326#SeeAlso incomplete
327
328#Method ##
329
330# ------------------------------------------------------------------------------
331
332#Method bool isEmbolden() const
333#In incomplete
334#Line # incomplete ##
335
336#Populate
337
338#Example
339// incomplete
340##
341
342#SeeAlso incomplete
343
344#Method ##
345
346# ------------------------------------------------------------------------------
347
348#Method void setForceAutoHinting(bool forceAutoHinting)
349#In incomplete
350#Line # incomplete ##
351
352#Populate
353
354#Example
355// incomplete
356##
357
358#SeeAlso incomplete
359
360#Method ##
361
362# ------------------------------------------------------------------------------
363
364#Method void setEmbeddedBitmaps(bool embeddedBitmaps)
365#In incomplete
366#Line # incomplete ##
367
368#Populate
369
370#Example
371// incomplete
372##
373
374#SeeAlso incomplete
375
376#Method ##
377
378# ------------------------------------------------------------------------------
379
380#Method void setSubpixel(bool subpixel)
381#In incomplete
382#Line # incomplete ##
383
384#Populate
385
386#Example
387// incomplete
388##
389
390#SeeAlso incomplete
391
392#Method ##
393
394# ------------------------------------------------------------------------------
395
396#Method void setLinearMetrics(bool linearMetrics)
397#In incomplete
398#Line # incomplete ##
399
400#Populate
401
402#Example
403// incomplete
404##
405
406#SeeAlso incomplete
407
408#Method ##
409
410# ------------------------------------------------------------------------------
411
412#Method void setEmbolden(bool embolden)
413#In incomplete
414#Line # incomplete ##
415
416#Populate
417
418#Example
419// incomplete
420##
421
422#SeeAlso incomplete
423
424#Method ##
425
426# ------------------------------------------------------------------------------
427
428#Method Edging getEdging() const
429#In incomplete
430#Line # incomplete ##
431
432#Populate
433
434#Example
435// incomplete
436##
437
438#SeeAlso incomplete
439
440#Method ##
441
442# ------------------------------------------------------------------------------
443
444#Method void setEdging(Edging edging)
445#In incomplete
446#Line # incomplete ##
447
448#Populate
449
450#Example
451// incomplete
452##
453
454#SeeAlso incomplete
455
456#Method ##
457
458# ------------------------------------------------------------------------------
459
460#Method void setHinting(SkFontHinting hintingLevel)
461#In incomplete
462#Line # incomplete ##
463
464#Populate
465
466#Example
467// incomplete
468##
469
470#SeeAlso incomplete
471
472#Method ##
473
474# ------------------------------------------------------------------------------
475
476#Method SkFontHinting getHinting() const
477#In incomplete
478#Line # incomplete ##
479
480#Populate
481
482#Example
483// incomplete
484##
485
486#SeeAlso incomplete
487
488#Method ##
489
490# ------------------------------------------------------------------------------
491
492#Method SkFont makeWithSize(SkScalar size) const
493#In incomplete
494#Line # incomplete ##
495
496#Populate
497
498#Example
499// incomplete
500##
501
502#SeeAlso incomplete
503
504#Method ##
505
506# ------------------------------------------------------------------------------
507
508#Method SkTypeface* getTypeface() const
509#In incomplete
510#Line # incomplete ##
511
512#Populate
513
514#Example
515// incomplete
516##
517
518#SeeAlso incomplete
519
520#Method ##
521
522# ------------------------------------------------------------------------------
523
524#Method SkScalar getSize() const
525#In incomplete
526#Line # incomplete ##
527
528#Populate
529
530#Example
531// incomplete
532##
533
534#SeeAlso incomplete
535
536#Method ##
537
538# ------------------------------------------------------------------------------
539
540#Method SkScalar getScaleX() const
541#In incomplete
542#Line # incomplete ##
543
544#Populate
545
546#Example
547// incomplete
548##
549
550#SeeAlso incomplete
551
552#Method ##
553
554# ------------------------------------------------------------------------------
555
556#Method SkScalar getSkewX() const
557#In incomplete
558#Line # incomplete ##
559
560#Populate
561
562#Example
563// incomplete
564##
565
566#SeeAlso incomplete
567
568#Method ##
569
570# ------------------------------------------------------------------------------
571
572#Method sk_sp<SkTypeface> refTypeface() const
573#In incomplete
574#Line # incomplete ##
575
576#Populate
577
578#Example
579// incomplete
580##
581
582#SeeAlso incomplete
583
584#Method ##
585
586# ------------------------------------------------------------------------------
587
588#Method void setTypeface(sk_sp<SkTypeface> tf)
589#In incomplete
590#Line # incomplete ##
591
592#Populate
593
594#Example
595// incomplete
596##
597
598#SeeAlso incomplete
599
600#Method ##
601
602# ------------------------------------------------------------------------------
603
604#Method void setSize(SkScalar textSize)
605#In incomplete
606#Line # incomplete ##
607
608#Populate
609
610#Example
611// incomplete
612##
613
614#SeeAlso incomplete
615
616#Method ##
617
618# ------------------------------------------------------------------------------
619
620#Method void setScaleX(SkScalar scaleX)
621#In incomplete
622#Line # incomplete ##
623
624#Populate
625
626#Example
627// incomplete
628##
629
630#SeeAlso incomplete
631
632#Method ##
633
634# ------------------------------------------------------------------------------
635
636#Method void setSkewX(SkScalar skewX)
637#In incomplete
638#Line # incomplete ##
639
640#Populate
641
642#Example
643// incomplete
644##
645
646#SeeAlso incomplete
647
648#Method ##
649
650# ------------------------------------------------------------------------------
651
652#Method int textToGlyphs(const void* text, size_t byteLength, SkTextEncoding encoding,
653 SkGlyphID glyphs[], int maxGlyphCount) const
Cary Clark26d173f2019-01-07 15:16:56 -0500654#In Utility
655#Line # converts text into glyph indices ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500656#Populate
657
658#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500659 #Height 64
660 void draw(SkCanvas* canvas) {
661 SkFont font;
662 const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
663 std::vector<SkGlyphID> glyphs;
664 int count = font.textToGlyphs(utf8, sizeof(utf8), SkTextEncoding::kUTF8, nullptr, 0);
665 glyphs.resize(count);
666 (void) font.textToGlyphs(utf8, sizeof(utf8), SkTextEncoding::kUTF8, &glyphs.front(),
667 count);
668 font.setSize(32);
669 canvas->drawSimpleText(&glyphs.front(), glyphs.size() * sizeof(SkGlyphID),
670 SkTextEncoding::kGlyphID, 10, 40, font, SkPaint());
671 }
Cary Clarkcb6bef02018-11-29 12:05:25 -0500672##
673
674#SeeAlso incomplete
675
676#Method ##
677
678# ------------------------------------------------------------------------------
679
680#Method uint16_t unicharToGlyph(SkUnichar uni) const
681#In incomplete
682#Line # incomplete ##
683
684#Populate
685
686#Example
687// incomplete
688##
689
690#SeeAlso incomplete
691
692#Method ##
693
694# ------------------------------------------------------------------------------
695
696#Method int countText(const void* text, size_t byteLength, SkTextEncoding encoding) const
Cary Clark26d173f2019-01-07 15:16:56 -0500697#In Utility
698#Line # returns number of Glyphs in text ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500699#Populate
700
701#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500702 SkFont font;
703 const uint8_t utf8[] = { 0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0xC2, 0xA5, 0xC2, 0xA3 };
704 SkDebugf("count = %d\n", font.countText(utf8, sizeof(utf8), SkTextEncoding::kUTF8));
705
706 #StdOut
707 count = 5
708 ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500709##
710
711#SeeAlso incomplete
712
713#Method ##
714
715# ------------------------------------------------------------------------------
716
Mike Reed42af4922018-11-30 08:54:46 -0500717#Method bool containsText(const void* text, size_t byteLength, SkTextEncoding encoding) const
Cary Clark26d173f2019-01-07 15:16:56 -0500718#In Utility
719#Line # returns if all text corresponds to Glyphs ##
Mike Reed42af4922018-11-30 08:54:46 -0500720#Populate
721
Cary Clark26d173f2019-01-07 15:16:56 -0500722#NoExample
723 #Description
724 containsText succeeds for degree symbol, but cannot find a glyph index
725 corresponding to the Unicode surrogate code point.
726 ##
727 SkFont font;
728 const uint16_t goodChar = 0x00B0; // degree symbol
729 const uint16_t badChar = 0xD800; // Unicode surrogate
730 SkDebugf("0x%04x %c= has char\n", goodChar,
731 font.containsText(&goodChar, 2, SkTextEncoding::kUTF16) ? '=' : '!');
732 SkDebugf("0x%04x %c= has char\n", badChar,
733 font.containsText(&badChar, 2, SkTextEncoding::kUTF16) ? '=' : '!');
734
735 #StdOut
736 0x00b0 == has char
737 0xd800 != has char
738 ##
739##
740
Mike Reed42af4922018-11-30 08:54:46 -0500741#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500742 #Description
743 containsText returns true that glyph index is greater than zero, not
744 that it corresponds to an entry in Typeface.
745 ##
746 SkFont font;
747 const uint16_t goodGlyph = 511;
748 const uint16_t zeroGlyph = 0;
749 const uint16_t badGlyph = 65535; // larger than glyph count in font
750 SkDebugf("0x%04x %c= has glyph\n", goodGlyph,
751 font.containsText(&goodGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
752 SkDebugf("0x%04x %c= has glyph\n", zeroGlyph,
753 font.containsText(&zeroGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
754 SkDebugf("0x%04x %c= has glyph\n", badGlyph,
755 font.containsText(&badGlyph, 2, SkTextEncoding::kGlyphID) ? '=' : '!');
756
757 #StdOut
758 0x01ff == has glyph
759 0x0000 != has glyph
760 0xffff == has glyph
761 ##
Mike Reed42af4922018-11-30 08:54:46 -0500762##
763
764#SeeAlso incomplete
765
766#Method ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500767
768# ------------------------------------------------------------------------------
Cary Clark5b671c32018-12-03 04:53:21 -0500769
770#Method size_t breakText(const void* text, size_t length, SkTextEncoding encoding, SkScalar maxWidth,
771 SkScalar* measuredWidth = nullptr) const
772#In incomplete
773#Line # incomplete ##
774#Populate
775
776#Example
Cary Clarke954b9d2018-12-10 09:22:56 -0500777 #Description
778 Line under "Breakfast" shows desired width, shorter than available characters.
779 Line under "Bre" shows measured width after breaking text.
780 ##
781 #Height 128
782 #Width 280
783 void draw(SkCanvas* canvas) {
784 SkPaint paint;
785 paint.setAntiAlias(true);
786 paint.setTextSize(50);
787 const char str[] = "Breakfast";
788 const int count = sizeof(str) - 1;
789 canvas->drawText(str, count, 25, 50, paint);
790 SkScalar measuredWidth;
791 SkFont font;
792 font.setSize(50);
793 int partialBytes = font.breakText(str, count, kUTF8_SkTextEncoding,
794 100, &measuredWidth);
795 canvas->drawText(str, partialBytes, 25, 100, paint);
796 canvas->drawLine(25, 60, 25 + 100, 60, paint);
797 canvas->drawLine(25, 110, 25 + measuredWidth, 110, paint);
798 }
Cary Clark5b671c32018-12-03 04:53:21 -0500799##
800
801#SeeAlso incomplete
802
803#Method ##
804
805# ------------------------------------------------------------------------------
Cary Clarkcb6bef02018-11-29 12:05:25 -0500806
807#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
808 SkRect* bounds = nullptr) const
809#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -0500810#Line # returns advance width and bounds of text ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500811#Populate
812
813#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500814 SkFont font;
815 SkDebugf("default width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
816 font.setSize(font.getSize() * 2);
817 SkDebugf("double width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
818
819 #StdOut
820 default width = 5
821 double width = 10
822 ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500823##
824
825#SeeAlso incomplete
826
827#Method ##
828
Cary Clark26d173f2019-01-07 15:16:56 -0500829
830#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
831 SkRect* bounds, const SkPaint* paint) const
832#In incomplete
833#Populate
834
835#Example
836 #Height 64
837 void draw(SkCanvas* canvas) {
838 SkPaint paint;
839 paint.setAntiAlias(true);
840 SkFont font(nullptr, 50);
841 const char str[] = "ay^jZ";
842 const int count = sizeof(str) - 1;
843 canvas->drawSimpleText(str, count, SkTextEncoding::kUTF8, 25, 50, font, paint);
844 SkRect bounds;
845 font.measureText(str, count, SkTextEncoding::kUTF8, &bounds, nullptr);
846 canvas->translate(25, 50);
847 paint.setStyle(SkPaint::kStroke_Style);
848 canvas->drawRect(bounds, paint);
849 }
850##
851
852#SeeAlso incomplete
853
854#Method ##
855
856#Method void getWidths(const uint16_t glyphs[], int count, SkScalar widths[]) const
857#In incomplete
858#Line # returns advance and bounds for each glyph in text ##
859#Populate
860#Example
861// incomplete
862##
863#SeeAlso incomplete
864#Method ##
865
866#Method void getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
867 const SkPaint* paint) const
868#In incomplete
869#Populate
870#Example
871 #Height 160
872 #Description
873 Bounds of Glyphs increase for stroked text, but text advance remains the same.
874 The underlines show the text advance, spaced to keep them distinct.
875 ##
876 void draw(SkCanvas* canvas) {
877 SkPaint paint;
878 paint.setAntiAlias(true);
879 SkFont font(nullptr, 50);
880 const char str[] = "abc";
881 const int bytes = sizeof(str) - 1;
882 int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
883 std::vector<SkGlyphID> glyphs;
884 std::vector<SkScalar> widths;
885 std::vector<SkRect> bounds;
886 glyphs.resize(count);
887 (void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
888 widths.resize(count);
889 bounds.resize(count);
890 for (int loop = 0; loop < 2; ++loop) {
891 (void) font.getWidthsBounds(&glyphs.front(), count, &widths.front(), &bounds.front(),
892 &paint);
893 SkPoint loc = { 25, 50 };
894 canvas->drawSimpleText(str, bytes, SkTextEncoding::kUTF8, loc.fX, loc.fY, font, paint);
895 paint.setStyle(SkPaint::kStroke_Style);
896 paint.setStrokeWidth(0);
897 SkScalar advanceY = loc.fY + 10;
898 for (int index = 0; index < count; ++index) {
899 bounds[index].offset(loc.fX, loc.fY);
900 canvas->drawRect(bounds[index], paint);
901 canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint);
902 loc.fX += widths[index];
903 advanceY += 5;
904 }
905 canvas->translate(0, 80);
906 paint.setStrokeWidth(3);
907 }
908 }
909##
910#SeeAlso incomplete
911#Method ##
912
913#Method void getBounds(const uint16_t glyphs[], int count, SkRect bounds[],
914 const SkPaint* paint) const
915#In incomplete
916#Populate
917#Example
918// incomplete
919##
920#SeeAlso incomplete
921#Method ##
922
923#Method void getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const
924#In incomplete
925#Populate
926#Example
927// incomplete
928##
929#SeeAlso incomplete
930#Method ##
931
932#Method void getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const
933#In incomplete
934#Populate
935#Example
936// incomplete
937##
938#SeeAlso incomplete
939#Method ##
940
Cary Clarkcb6bef02018-11-29 12:05:25 -0500941# ------------------------------------------------------------------------------
942
943#Method bool getPath(uint16_t glyphID, SkPath* path) const
944#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -0500945#Line # returns Path equivalent to text ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500946#Populate
947
948#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500949 #Description
950 Text is added to Path, offset, and subtracted from Path, then added at
951 the offset location. The result is rendered with one draw call.
952 ##
953 #Height 128
954 void draw(SkCanvas* canvas) {
955 SkPaint paint;
956 SkFont font(nullptr, 80);
957 SkPath onePath, path, path2;
958 const char str[] = "ABC";
959 const int bytes = sizeof(str) - 1;
960 int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
961 std::vector<SkGlyphID> glyphs;
962 glyphs.resize(count);
963 (void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
964 int xPos = 20;
965 for (auto oneGlyph : glyphs) {
966 font.getPath(oneGlyph, &onePath);
967 path.addPath(onePath, xPos, 60);
968 xPos += 60;
969 }
970 path.offset(20, 20, &path2);
971 Op(path, path2, SkPathOp::kDifference_SkPathOp, &path);
972 path.addPath(path2);
973 paint.setStyle(SkPaint::kStroke_Style);
974 canvas->drawPath(path, paint);
975 }
Cary Clarkcb6bef02018-11-29 12:05:25 -0500976##
977
978#SeeAlso incomplete
979
980#Method ##
981
982# ------------------------------------------------------------------------------
983
984#Method void getPaths(const uint16_t glyphIDs[], int count,
985 void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
986 void* ctx) const
987#In incomplete
988#Line # incomplete ##
989
990#Populate
991
992#Example
993// incomplete
994##
995
996#SeeAlso incomplete
997
998#Method ##
999
1000# ------------------------------------------------------------------------------
1001
1002#Method SkScalar getMetrics(SkFontMetrics* metrics) const
1003#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -05001004#Line # returns Typeface metrics scaled by text size ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001005#Populate
1006
1007#Example
Cary Clark26d173f2019-01-07 15:16:56 -05001008 #Height 128
1009 void draw(SkCanvas* canvas) {
1010 SkFont font(nullptr, 32);
1011 SkScalar lineHeight = font.getMetrics(nullptr);
1012 SkPaint paint;
1013 canvas->drawSimpleText("line 1", 6, SkTextEncoding::kUTF8, 10, 40, font, paint);
1014 canvas->drawSimpleText("line 2", 6, SkTextEncoding::kUTF8, 10, 40 + lineHeight, font, paint);
1015 }
Cary Clarkcb6bef02018-11-29 12:05:25 -05001016##
1017
1018#SeeAlso incomplete
1019
1020#Method ##
1021
1022# ------------------------------------------------------------------------------
1023
1024#Method SkScalar getSpacing() const
1025#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -05001026#Line # returns recommended spacing between lines ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001027
1028#Populate
1029
1030#Example
Cary Clark26d173f2019-01-07 15:16:56 -05001031 SkFont font;
1032 for (SkScalar textSize : { 12, 18, 24, 32 } ) {
1033 font.setSize(textSize);
1034 SkDebugf("textSize: %g spacing: %g\n", textSize, font.getSpacing());
1035 }
1036
1037 #StdOut
1038 textSize: 12 spacing: 13.9688
1039 textSize: 18 spacing: 20.9531
1040 textSize: 24 spacing: 27.9375
1041 textSize: 32 spacing: 37.25
1042 ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001043##
1044
1045#SeeAlso incomplete
1046
1047#Method ##
1048
1049# ------------------------------------------------------------------------------
1050
1051#Class SkFont ##
1052
1053#Topic Font ##