Home | History | Annotate | Download | only in docs
      1 #Topic Text_Blob_Builder
      2 #Alias Text_Blob_Builder_Reference ##
      3 
      4 #Class SkTextBlobBuilder
      5 
      6 #Code
      7 #Populate
      8 ##
      9 
     10 Helper class for constructing SkTextBlob.
     11 
     12 # ------------------------------------------------------------------------------
     13 
     14 #Struct RunBuffer
     15 #Line # storage for Glyphs and Glyph positions ##
     16 
     17 #Code
     18     struct RunBuffer {
     19         SkGlyphID* glyphs;
     20         SkScalar* pos;
     21         char* utf8text;
     22         uint32_t* clusters;
     23     };
     24 ##
     25 
     26 RunBuffer supplies storage for Glyphs and positions within a run.
     27 
     28 A run is a sequence of Glyphs sharing Font_Metrics and positioning.
     29 Each run may position its Glyphs in one of three ways:
     30 by specifying where the first Glyph is drawn, and allowing Font_Metrics to
     31 determine the advance to subsequent Glyphs; by specifying a baseline, and
     32 the position on that baseline for each Glyph in run; or by providing Point
     33 array, one per Glyph.
     34 
     35 #Member SkGlyphID* glyphs
     36 #Line # storage for Glyphs in run ##
     37     glyphs points to memory for one or more Glyphs. glyphs memory must be
     38     written to by the caller.
     39 ##
     40 
     41 #Member SkScalar* pos
     42 #Line # storage for positions in run ##
     43     pos points to memory for Glyph positions. Depending on how RunBuffer
     44     is allocated, pos may point to zero bytes per Glyph, one Scalar per Glyph,
     45     or one Point per Glyph.
     46 ##
     47 
     48 #Member char* utf8text
     49 #Line # reserved for future use ##
     50     Reserved for future use. utf8text should not be read or written.
     51 ##
     52 
     53 #Member uint32_t* clusters
     54 #Line # reserved for future use ##
     55     Reserved for future use. clusters should not be read or written.
     56 ##
     57 
     58 #SeeAlso allocRun allocRunPos allocRunPosH
     59 
     60 #Struct RunBuffer ##
     61 
     62 # ------------------------------------------------------------------------------
     63 
     64 #Method SkTextBlobBuilder()
     65 #In Constructors
     66 #Line # constructs with default values ##
     67 #Populate
     68 
     69 #Example
     70     SkTextBlobBuilder builder;
     71     sk_sp<SkTextBlob> blob = builder.make();
     72     SkDebugf("blob " "%s" " nullptr", blob == nullptr ? "equals" : "does not equal");
     73 #StdOut
     74 blob equals nullptr
     75 ##
     76 ##
     77 
     78 #SeeAlso make SkTextBlob::MakeFromText
     79 
     80 #Method ##
     81 
     82 # ------------------------------------------------------------------------------
     83 
     84 #Method ~SkTextBlobBuilder()
     85 #In Constructors
     86 #Line # deletes storage ##
     87 #Populate
     88 
     89 #NoExample
     90 ##
     91 
     92 #SeeAlso SkTextBlobBuilder()
     93 
     94 #Method ##
     95 
     96 # ------------------------------------------------------------------------------
     97 
     98 #Method sk_sp<SkTextBlob> make()
     99 #In Constructors
    100 #Line # constructs Text_Blob from bulider ##
    101 #Populate
    102 
    103 #Example
    104     SkTextBlobBuilder builder;
    105     sk_sp<SkTextBlob> blob = builder.make();
    106     SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
    107     SkPaint paint;
    108     paint.setTextEncoding(kGlyphID_SkTextEncoding);
    109     SkFont font;
    110     paint.textToGlyphs("x", 1, builder.allocRun(font, 1, 20, 20).glyphs);
    111     blob = builder.make();
    112     SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
    113     blob = builder.make();
    114     SkDebugf("blob " "%s" " nullptr\n", blob == nullptr ? "equals" : "does not equal");
    115 #StdOut
    116 blob equals nullptr
    117 blob does not equal nullptr
    118 blob equals nullptr
    119 ##
    120 ##
    121 
    122 #SeeAlso SkTextBlob::MakeFromText
    123 
    124 #Method ##
    125 
    126 # ------------------------------------------------------------------------------
    127 
    128 #Method const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
    129 const SkRect* bounds = nullptr)
    130 #In Allocator
    131 #Line # returns writable glyph buffer at Point ##
    132 
    133 #Populate
    134 
    135 #Example
    136 #Height 60
    137     SkTextBlobBuilder builder;
    138     SkFont font;
    139     SkPaint paint;
    140     const SkTextBlobBuilder::RunBuffer& run = builder.allocRun(font, 5, 20, 20);
    141     paint.textToGlyphs("hello", 5, run.glyphs);
    142     canvas->drawRect({20, 20, 30, 30}, paint);
    143     canvas->drawTextBlob(builder.make(), 20, 20, paint);
    144 ##
    145 
    146 #SeeAlso allocRunPosH allocRunPos
    147 
    148 #Method ##
    149 
    150 # ------------------------------------------------------------------------------
    151 
    152 #Method const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
    153                                       const SkRect* bounds = nullptr)
    154 #In Allocator
    155 #Line # returns writable glyph and x-axis position buffers ##
    156 
    157 #Populate
    158 
    159 #Example
    160 #Height 60
    161     SkTextBlobBuilder builder;
    162     SkPaint paint;
    163     SkFont font;
    164     const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPosH(font, 5, 20);
    165     paint.textToGlyphs("hello", 5, run.glyphs);
    166     SkScalar positions[] = {0, 10, 20, 40, 80};
    167     memcpy(run.pos, positions, sizeof(positions));
    168     canvas->drawTextBlob(builder.make(), 20, 20, paint);
    169 ##
    170 
    171 #SeeAlso allocRunPos allocRun
    172 
    173 #Method ##
    174 
    175 # ------------------------------------------------------------------------------
    176 
    177 #Method const RunBuffer& allocRunPos(const SkFont& font, int count,
    178                                      const SkRect* bounds = nullptr)
    179 #In Allocator
    180 #Line # returns writable glyph and Point buffers ##
    181 
    182 #Populate
    183 
    184 #Example
    185 #Height 90
    186     SkTextBlobBuilder builder;
    187     SkPaint paint;
    188     SkFont font;
    189     const SkTextBlobBuilder::RunBuffer& run = builder.allocRunPos(font, 5);
    190     paint.textToGlyphs("hello", 5, run.glyphs);
    191     SkPoint positions[] = {{0, 0}, {10, 10}, {20, 20}, {40, 40}, {80, 80}};
    192     memcpy(run.pos, positions, sizeof(positions));
    193     canvas->drawTextBlob(builder.make(), 20, 20, paint);
    194 ##
    195 
    196 #SeeAlso allocRunPosH allocRun
    197 
    198 #Method ##
    199 
    200 #Class SkTextBlobBuilder ##
    201 
    202 #Topic Text_Blob_Builder ##
    203