OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2000 Dirk Mueller (mueller@kde.org) | 4 * (C) 2000 Dirk Mueller (mueller@kde.org) |
5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. | 5 * Copyright (C) 2003, 2006, 2010, 2011 Apple Inc. All rights reserved. |
6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. | 6 * Copyright (c) 2007, 2008, 2010 Google Inc. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 #if ENABLE(SVG_FONTS) | 264 #if ENABLE(SVG_FONTS) |
265 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) | 265 if (TextRun::RenderingContext* renderingContext = run.renderingContext()) |
266 return renderingContext->floatWidthUsingSVGFont(*this, run, charsConsume
d, glyphId); | 266 return renderingContext->floatWidthUsingSVGFont(*this, run, charsConsume
d, glyphId); |
267 #endif | 267 #endif |
268 | 268 |
269 charsConsumed = run.length(); | 269 charsConsumed = run.length(); |
270 glyphId = 0; | 270 glyphId = 0; |
271 return width(run); | 271 return width(run); |
272 } | 272 } |
273 | 273 |
274 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia
lAdvance, | 274 namespace { |
275 const FloatRect& bounds, bool couldUseLCD) const | 275 |
| 276 template <bool hasOffsets> |
| 277 bool buildTextBlobInternal(const GlyphBuffer& glyphBuffer, SkScalar initialAdvan
ce, |
| 278 const SkRect* bounds, bool couldUseLCD, SkTextBlobBuilder& builder) |
276 { | 279 { |
277 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); | 280 SkScalar x = initialAdvance; |
278 | |
279 // FIXME: Implement the more general full-positioning path for complex text
support. | |
280 if (glyphBuffer.hasOffsets()) | |
281 return nullptr; | |
282 | |
283 SkTextBlobBuilder builder; | |
284 SkScalar x = SkFloatToScalar(initialAdvance); | |
285 SkRect skBounds = bounds; | |
286 | |
287 unsigned i = 0; | 281 unsigned i = 0; |
288 while (i < glyphBuffer.size()) { | 282 while (i < glyphBuffer.size()) { |
289 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i); | 283 const SimpleFontData* fontData = glyphBuffer.fontDataAt(i); |
290 | 284 |
291 // FIXME: Handle vertical text. | 285 // FIXME: Handle vertical text. |
292 if (fontData->platformData().orientation() == Vertical) | 286 if (fontData->platformData().orientation() == Vertical) |
293 return nullptr; | 287 return false; |
294 | 288 |
295 // FIXME: Handle SVG fonts. | 289 // FIXME: Handle SVG fonts. |
296 if (fontData->isSVGFont()) | 290 if (fontData->isSVGFont()) |
297 return nullptr; | 291 return false; |
298 | 292 |
299 // FIXME: FontPlatformData makes some decisions on the device scale | 293 // FIXME: FontPlatformData makes some decisions on the device scale |
300 // factor, which is found via the GraphicsContext. This should be fixed | 294 // factor, which is found via the GraphicsContext. This should be fixed |
301 // to avoid correctness problems here. | 295 // to avoid correctness problems here. |
302 SkPaint paint; | 296 SkPaint paint; |
303 fontData->platformData().setupPaint(&paint); | 297 fontData->platformData().setupPaint(&paint); |
304 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 298 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
305 | 299 |
306 // FIXME: this should go away after the big LCD cleanup. | 300 // FIXME: this should go away after the big LCD cleanup. |
307 paint.setLCDRenderText(paint.isLCDRenderText() && couldUseLCD); | 301 paint.setLCDRenderText(paint.isLCDRenderText() && couldUseLCD); |
308 | 302 |
309 unsigned start = i++; | 303 unsigned start = i++; |
310 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData) | 304 while (i < glyphBuffer.size() && glyphBuffer.fontDataAt(i) == fontData) |
311 i++; | 305 i++; |
312 unsigned count = i - start; | 306 unsigned count = i - start; |
313 | 307 |
314 const SkTextBlobBuilder::RunBuffer& buffer = builder.allocRunPosH(paint,
count, 0, &skBounds); | 308 const SkTextBlobBuilder::RunBuffer& buffer = hasOffsets ? |
| 309 builder.allocRunPos(paint, count, bounds) : |
| 310 builder.allocRunPosH(paint, count, 0, bounds); |
315 | 311 |
316 const uint16_t* glyphs = glyphBuffer.glyphs(start); | 312 const uint16_t* glyphs = glyphBuffer.glyphs(start); |
317 std::copy(glyphs, glyphs + count, buffer.glyphs); | 313 std::copy(glyphs, glyphs + count, buffer.glyphs); |
318 | 314 |
319 const float* advances = glyphBuffer.advances(start); | 315 const float* advances = glyphBuffer.advances(start); |
| 316 const FloatSize* offsets = glyphBuffer.offsets(start); |
320 for (unsigned j = 0; j < count; j++) { | 317 for (unsigned j = 0; j < count; j++) { |
321 buffer.pos[j] = x; | 318 if (hasOffsets) { |
| 319 const FloatSize& offset = offsets[j]; |
| 320 buffer.pos[2 * j] = x + offset.width(); |
| 321 buffer.pos[2 * j + 1] = offset.height(); |
| 322 } else { |
| 323 buffer.pos[j] = x; |
| 324 } |
322 x += SkFloatToScalar(advances[j]); | 325 x += SkFloatToScalar(advances[j]); |
323 } | 326 } |
324 } | 327 } |
| 328 return true; |
| 329 } |
325 | 330 |
326 return adoptRef(builder.build()); | 331 } // namespace |
| 332 |
| 333 PassTextBlobPtr Font::buildTextBlob(const GlyphBuffer& glyphBuffer, float initia
lAdvance, |
| 334 const FloatRect& bounds, bool couldUseLCD) const |
| 335 { |
| 336 ASSERT(RuntimeEnabledFeatures::textBlobEnabled()); |
| 337 |
| 338 SkTextBlobBuilder builder; |
| 339 SkScalar advance = SkFloatToScalar(initialAdvance); |
| 340 SkRect skBounds = bounds; |
| 341 |
| 342 bool success = glyphBuffer.hasOffsets() ? |
| 343 buildTextBlobInternal<true>(glyphBuffer, advance, &skBounds, couldUseLCD
, builder) : |
| 344 buildTextBlobInternal<false>(glyphBuffer, advance, &skBounds, couldUseLC
D, builder); |
| 345 return success ? adoptRef(builder.build()) : nullptr; |
327 } | 346 } |
328 | 347 |
329 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) | 348 static inline FloatRect pixelSnappedSelectionRect(FloatRect rect) |
330 { | 349 { |
331 // Using roundf() rather than ceilf() for the right edge as a compromise to | 350 // Using roundf() rather than ceilf() for the right edge as a compromise to |
332 // ensure correct caret positioning. | 351 // ensure correct caret positioning. |
333 float roundedX = roundf(rect.x()); | 352 float roundedX = roundf(rect.x()); |
334 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), rect.he
ight()); | 353 return FloatRect(roundedX, rect.y(), roundf(rect.maxX() - roundedX), rect.he
ight()); |
335 } | 354 } |
336 | 355 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 if (delta <= 0) | 1131 if (delta <= 0) |
1113 break; | 1132 break; |
1114 } | 1133 } |
1115 } | 1134 } |
1116 } | 1135 } |
1117 | 1136 |
1118 return offset; | 1137 return offset; |
1119 } | 1138 } |
1120 | 1139 |
1121 } // namespace blink | 1140 } // namespace blink |
OLD | NEW |