203 void Font::render(SkPaint* paint, const char *text, uint32_t start, uint32_t len,
204 int numGlyphs, SkPath* path, float hOffset, float vOffset) {
205 if (numGlyphs == 0 || text == NULL || len == 0) {
206 return;
207 }
208
209 text += start;
210
211 int glyphsCount = 0;
212 SkFixed prevRsbDelta = 0;
213
214 float penX = 0.0f;
215
216 SkPoint position;
217 SkVector tangent;
218
219 SkPathMeasure measure(*path, false);
220 float pathLength = SkScalarToFloat(measure.getLength());
221
222 if (paint->getTextAlign() != SkPaint::kLeft_Align) {
223 float textWidth = SkScalarToFloat(paint->measureText(text, len));
224 float pathOffset = pathLength;
225 if (paint->getTextAlign() == SkPaint::kCenter_Align) {
226 textWidth *= 0.5f;
227 pathOffset *= 0.5f;
228 }
229 penX += pathOffset - textWidth;
230 }
231
232 while (glyphsCount < numGlyphs && penX < pathLength) {
233 glyph_t glyph = GET_GLYPH(text);
234
235 if (IS_END_OF_STRING(glyph)) {
236 break;
237 }
238
239 CachedGlyphInfo* cachedGlyph = getCachedGlyph(paint, glyph);
240 penX += SkFixedToFloat(AUTO_KERN(prevRsbDelta, cachedGlyph->mLsbDelta));
241 prevRsbDelta = cachedGlyph->mRsbDelta;
242
243 if (cachedGlyph->mIsValid) {
244 drawCachedGlyph(cachedGlyph, penX, hOffset, vOffset, measure, &position, &tangent);
245 }
246
247 penX += SkFixedToFloat(cachedGlyph->mAdvanceX);
248
249 glyphsCount++;
250 }
251 }