blob: 7d5bbef1068de45f54de30154789f3be5357ce53 [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;
Hal Canary532c4182019-01-09 11:37:29 -0500785 SkFont font(nullptr, 50);
Cary Clarke954b9d2018-12-10 09:22:56 -0500786 const char str[] = "Breakfast";
Hal Canary532c4182019-01-09 11:37:29 -0500787 const int count = strlen(str);
788 canvas->drawSimpleText(str, count, kUTF8_SkTextEncoding,
789 25, 50, font, paint);
Cary Clarke954b9d2018-12-10 09:22:56 -0500790 SkScalar measuredWidth;
Cary Clarke954b9d2018-12-10 09:22:56 -0500791 int partialBytes = font.breakText(str, count, kUTF8_SkTextEncoding,
Hal Canary532c4182019-01-09 11:37:29 -0500792 100, &measuredWidth);
793 canvas->drawSimpleText(str, partialBytes, kUTF8_SkTextEncoding,
794 25, 100, font, paint);
Cary Clarke954b9d2018-12-10 09:22:56 -0500795 canvas->drawLine(25, 60, 25 + 100, 60, paint);
796 canvas->drawLine(25, 110, 25 + measuredWidth, 110, paint);
797 }
Cary Clark5b671c32018-12-03 04:53:21 -0500798##
799
800#SeeAlso incomplete
801
802#Method ##
803
804# ------------------------------------------------------------------------------
Cary Clarkcb6bef02018-11-29 12:05:25 -0500805
806#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
807 SkRect* bounds = nullptr) const
808#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -0500809#Line # returns advance width and bounds of text ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500810#Populate
811
812#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500813 SkFont font;
814 SkDebugf("default width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
815 font.setSize(font.getSize() * 2);
816 SkDebugf("double width = %g\n", font.measureText("!", 1, SkTextEncoding::kUTF8));
817
818 #StdOut
819 default width = 5
820 double width = 10
821 ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500822##
823
824#SeeAlso incomplete
825
826#Method ##
827
Cary Clark26d173f2019-01-07 15:16:56 -0500828
829#Method SkScalar measureText(const void* text, size_t byteLength, SkTextEncoding encoding,
830 SkRect* bounds, const SkPaint* paint) const
831#In incomplete
832#Populate
833
834#Example
835 #Height 64
836 void draw(SkCanvas* canvas) {
837 SkPaint paint;
838 paint.setAntiAlias(true);
839 SkFont font(nullptr, 50);
840 const char str[] = "ay^jZ";
841 const int count = sizeof(str) - 1;
842 canvas->drawSimpleText(str, count, SkTextEncoding::kUTF8, 25, 50, font, paint);
843 SkRect bounds;
844 font.measureText(str, count, SkTextEncoding::kUTF8, &bounds, nullptr);
845 canvas->translate(25, 50);
846 paint.setStyle(SkPaint::kStroke_Style);
847 canvas->drawRect(bounds, paint);
848 }
849##
850
851#SeeAlso incomplete
852
853#Method ##
854
855#Method void getWidths(const uint16_t glyphs[], int count, SkScalar widths[]) const
856#In incomplete
857#Line # returns advance and bounds for each glyph in text ##
858#Populate
859#Example
860// incomplete
861##
862#SeeAlso incomplete
863#Method ##
864
865#Method void getWidthsBounds(const uint16_t glyphs[], int count, SkScalar widths[], SkRect bounds[],
866 const SkPaint* paint) const
867#In incomplete
868#Populate
869#Example
870 #Height 160
871 #Description
872 Bounds of Glyphs increase for stroked text, but text advance remains the same.
873 The underlines show the text advance, spaced to keep them distinct.
874 ##
875 void draw(SkCanvas* canvas) {
876 SkPaint paint;
877 paint.setAntiAlias(true);
878 SkFont font(nullptr, 50);
879 const char str[] = "abc";
880 const int bytes = sizeof(str) - 1;
881 int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
882 std::vector<SkGlyphID> glyphs;
883 std::vector<SkScalar> widths;
884 std::vector<SkRect> bounds;
885 glyphs.resize(count);
886 (void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
887 widths.resize(count);
888 bounds.resize(count);
889 for (int loop = 0; loop < 2; ++loop) {
890 (void) font.getWidthsBounds(&glyphs.front(), count, &widths.front(), &bounds.front(),
891 &paint);
892 SkPoint loc = { 25, 50 };
893 canvas->drawSimpleText(str, bytes, SkTextEncoding::kUTF8, loc.fX, loc.fY, font, paint);
894 paint.setStyle(SkPaint::kStroke_Style);
895 paint.setStrokeWidth(0);
896 SkScalar advanceY = loc.fY + 10;
897 for (int index = 0; index < count; ++index) {
898 bounds[index].offset(loc.fX, loc.fY);
899 canvas->drawRect(bounds[index], paint);
900 canvas->drawLine(loc.fX, advanceY, loc.fX + widths[index], advanceY, paint);
901 loc.fX += widths[index];
902 advanceY += 5;
903 }
904 canvas->translate(0, 80);
905 paint.setStrokeWidth(3);
906 }
907 }
908##
909#SeeAlso incomplete
910#Method ##
911
912#Method void getBounds(const uint16_t glyphs[], int count, SkRect bounds[],
913 const SkPaint* paint) const
914#In incomplete
915#Populate
916#Example
917// incomplete
918##
919#SeeAlso incomplete
920#Method ##
921
922#Method void getPos(const uint16_t glyphs[], int count, SkPoint pos[], SkPoint origin = {0, 0}) const
923#In incomplete
924#Populate
925#Example
926// incomplete
927##
928#SeeAlso incomplete
929#Method ##
930
931#Method void getXPos(const uint16_t glyphs[], int count, SkScalar xpos[], SkScalar origin = 0) const
932#In incomplete
933#Populate
934#Example
935// incomplete
936##
937#SeeAlso incomplete
938#Method ##
939
Cary Clarkcb6bef02018-11-29 12:05:25 -0500940# ------------------------------------------------------------------------------
941
942#Method bool getPath(uint16_t glyphID, SkPath* path) const
943#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -0500944#Line # returns Path equivalent to text ##
Cary Clarkcb6bef02018-11-29 12:05:25 -0500945#Populate
946
947#Example
Cary Clark26d173f2019-01-07 15:16:56 -0500948 #Description
949 Text is added to Path, offset, and subtracted from Path, then added at
950 the offset location. The result is rendered with one draw call.
951 ##
952 #Height 128
953 void draw(SkCanvas* canvas) {
954 SkPaint paint;
955 SkFont font(nullptr, 80);
956 SkPath onePath, path, path2;
957 const char str[] = "ABC";
958 const int bytes = sizeof(str) - 1;
959 int count = font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, nullptr, 0);
960 std::vector<SkGlyphID> glyphs;
961 glyphs.resize(count);
962 (void) font.textToGlyphs(str, bytes, SkTextEncoding::kUTF8, &glyphs.front(), count);
963 int xPos = 20;
964 for (auto oneGlyph : glyphs) {
965 font.getPath(oneGlyph, &onePath);
966 path.addPath(onePath, xPos, 60);
967 xPos += 60;
968 }
969 path.offset(20, 20, &path2);
970 Op(path, path2, SkPathOp::kDifference_SkPathOp, &path);
971 path.addPath(path2);
972 paint.setStyle(SkPaint::kStroke_Style);
973 canvas->drawPath(path, paint);
974 }
Cary Clarkcb6bef02018-11-29 12:05:25 -0500975##
976
977#SeeAlso incomplete
978
979#Method ##
980
981# ------------------------------------------------------------------------------
982
983#Method void getPaths(const uint16_t glyphIDs[], int count,
984 void (*glyphPathProc)(const SkPath* pathOrNull, const SkMatrix& mx, void* ctx),
985 void* ctx) const
986#In incomplete
987#Line # incomplete ##
988
989#Populate
990
991#Example
992// incomplete
993##
994
995#SeeAlso incomplete
996
997#Method ##
998
999# ------------------------------------------------------------------------------
1000
1001#Method SkScalar getMetrics(SkFontMetrics* metrics) const
1002#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -05001003#Line # returns Typeface metrics scaled by text size ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001004#Populate
1005
1006#Example
Cary Clark26d173f2019-01-07 15:16:56 -05001007 #Height 128
1008 void draw(SkCanvas* canvas) {
1009 SkFont font(nullptr, 32);
1010 SkScalar lineHeight = font.getMetrics(nullptr);
1011 SkPaint paint;
1012 canvas->drawSimpleText("line 1", 6, SkTextEncoding::kUTF8, 10, 40, font, paint);
1013 canvas->drawSimpleText("line 2", 6, SkTextEncoding::kUTF8, 10, 40 + lineHeight, font, paint);
1014 }
Cary Clarkcb6bef02018-11-29 12:05:25 -05001015##
1016
1017#SeeAlso incomplete
1018
1019#Method ##
1020
1021# ------------------------------------------------------------------------------
1022
1023#Method SkScalar getSpacing() const
1024#In incomplete
Cary Clark26d173f2019-01-07 15:16:56 -05001025#Line # returns recommended spacing between lines ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001026
1027#Populate
1028
1029#Example
Cary Clark26d173f2019-01-07 15:16:56 -05001030 SkFont font;
1031 for (SkScalar textSize : { 12, 18, 24, 32 } ) {
1032 font.setSize(textSize);
1033 SkDebugf("textSize: %g spacing: %g\n", textSize, font.getSpacing());
1034 }
1035
1036 #StdOut
1037 textSize: 12 spacing: 13.9688
1038 textSize: 18 spacing: 20.9531
1039 textSize: 24 spacing: 27.9375
1040 textSize: 32 spacing: 37.25
1041 ##
Cary Clarkcb6bef02018-11-29 12:05:25 -05001042##
1043
1044#SeeAlso incomplete
1045
1046#Method ##
1047
1048# ------------------------------------------------------------------------------
1049
1050#Class SkFont ##
1051
1052#Topic Font ##