Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: Source/core/platform/graphics/FontFastPath.cpp

Issue 14160005: Track the region where text is painted. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rebase with TOT Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 /** 1 /**
2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Holger Hans Peter Freyther 3 * Copyright (C) 2008 Holger Hans Peter Freyther
4 * Copyright (C) 2009 Torch Mobile, Inc. 4 * Copyright (C) 2009 Torch Mobile, Inc.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth; 436 initialAdvance = finalRoundingWidth + it.m_runWidthSoFar - afterWidth;
437 } else 437 } else
438 initialAdvance = beforeWidth; 438 initialAdvance = beforeWidth;
439 439
440 if (run.rtl()) 440 if (run.rtl())
441 glyphBuffer.reverse(0, glyphBuffer.size()); 441 glyphBuffer.reverse(0, glyphBuffer.size());
442 442
443 return initialAdvance; 443 return initialAdvance;
444 } 444 }
445 445
446 void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Fl oatPoint& point, int from, int to) const 446 void Font::drawSimpleText(GraphicsContext* context, const TextRun& run, const Fl oatPoint& point, const FloatRect& textRect, int from, int to) const
447 { 447 {
448 // This glyph buffer holds our glyphs+advances+font data for each glyph. 448 // This glyph buffer holds our glyphs+advances+font data for each glyph.
449 GlyphBuffer glyphBuffer; 449 GlyphBuffer glyphBuffer;
450 450
451 float startX = point.x() + getGlyphsAndAdvancesForSimpleText(run, from, to, glyphBuffer); 451 float startX = point.x() + getGlyphsAndAdvancesForSimpleText(run, from, to, glyphBuffer);
452 452
453 if (glyphBuffer.isEmpty()) 453 if (glyphBuffer.isEmpty())
454 return; 454 return;
455 455
456 FloatPoint startPoint(startX, point.y()); 456 FloatPoint startPoint(startX, point.y());
457 drawGlyphBuffer(context, run, glyphBuffer, startPoint); 457 drawGlyphBuffer(context, run, glyphBuffer, startPoint, textRect);
458 } 458 }
459 459
460 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRu n& run, const AtomicString& mark, const FloatPoint& point, int from, int to) con st 460 void Font::drawEmphasisMarksForSimpleText(GraphicsContext* context, const TextRu n& run, const AtomicString& mark, const FloatPoint& point, const FloatRect& text Rect, int from, int to) const
461 { 461 {
462 GlyphBuffer glyphBuffer; 462 GlyphBuffer glyphBuffer;
463 float initialAdvance = getGlyphsAndAdvancesForSimpleText(run, from, to, glyp hBuffer, ForTextEmphasis); 463 float initialAdvance = getGlyphsAndAdvancesForSimpleText(run, from, to, glyp hBuffer, ForTextEmphasis);
464 464
465 if (glyphBuffer.isEmpty()) 465 if (glyphBuffer.isEmpty())
466 return; 466 return;
467 467
468 drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + in itialAdvance, point.y())); 468 drawEmphasisMarks(context, run, glyphBuffer, mark, FloatPoint(point.x() + in itialAdvance, point.y()), textRect);
469 } 469 }
470 470
471 void Font::drawGlyphBuffer(GraphicsContext* context, const TextRun& run, const G lyphBuffer& glyphBuffer, const FloatPoint& point) const 471 void Font::drawGlyphBuffer(GraphicsContext* context, const TextRun& run, const G lyphBuffer& glyphBuffer, const FloatPoint& point, const FloatRect& textRect) con st
472 { 472 {
473 #if !ENABLE(SVG_FONTS) 473 #if !ENABLE(SVG_FONTS)
474 UNUSED_PARAM(run); 474 UNUSED_PARAM(run);
475 #endif 475 #endif
476 476
477 // Draw each contiguous run of glyphs that use the same font data. 477 // Draw each contiguous run of glyphs that use the same font data.
478 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); 478 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0);
479 FloatSize offset = glyphBuffer.offsetAt(0); 479 FloatSize offset = glyphBuffer.offsetAt(0);
480 FloatPoint startPoint(point); 480 FloatPoint startPoint(point);
481 float nextX = startPoint.x() + glyphBuffer.advanceAt(0); 481 float nextX = startPoint.x() + glyphBuffer.advanceAt(0);
482 int lastFrom = 0; 482 int lastFrom = 0;
483 int nextGlyph = 1; 483 int nextGlyph = 1;
484 #if ENABLE(SVG_FONTS) 484 #if ENABLE(SVG_FONTS)
485 TextRun::RenderingContext* renderingContext = run.renderingContext(); 485 TextRun::RenderingContext* renderingContext = run.renderingContext();
486 #endif 486 #endif
487 while (nextGlyph < glyphBuffer.size()) { 487 while (nextGlyph < glyphBuffer.size()) {
488 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); 488 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph);
489 FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph); 489 FloatSize nextOffset = glyphBuffer.offsetAt(nextGlyph);
490 490
491 if (nextFontData != fontData || nextOffset != offset) { 491 if (nextFontData != fontData || nextOffset != offset) {
492 #if ENABLE(SVG_FONTS) 492 #if ENABLE(SVG_FONTS)
493 if (renderingContext && fontData->isSVGFont()) 493 if (renderingContext && fontData->isSVGFont())
494 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuf fer, lastFrom, nextGlyph - lastFrom, startPoint); 494 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuf fer, lastFrom, nextGlyph - lastFrom, startPoint);
495 else 495 else
496 #endif 496 #endif
497 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint); 497 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFrom, startPoint, textRect);
498 498
499 lastFrom = nextGlyph; 499 lastFrom = nextGlyph;
500 fontData = nextFontData; 500 fontData = nextFontData;
501 offset = nextOffset; 501 offset = nextOffset;
502 startPoint.setX(nextX); 502 startPoint.setX(nextX);
503 } 503 }
504 nextX += glyphBuffer.advanceAt(nextGlyph); 504 nextX += glyphBuffer.advanceAt(nextGlyph);
505 nextGlyph++; 505 nextGlyph++;
506 } 506 }
507 507
508 #if ENABLE(SVG_FONTS) 508 #if ENABLE(SVG_FONTS)
509 if (renderingContext && fontData->isSVGFont()) 509 if (renderingContext && fontData->isSVGFont())
510 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, las tFrom, nextGlyph - lastFrom, startPoint); 510 renderingContext->drawSVGGlyphs(context, run, fontData, glyphBuffer, las tFrom, nextGlyph - lastFrom, startPoint);
511 else 511 else
512 #endif 512 #endif
513 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro m, startPoint); 513 drawGlyphs(context, fontData, glyphBuffer, lastFrom, nextGlyph - lastFro m, startPoint, textRect);
514 } 514 }
515 515
516 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph) 516 inline static float offsetToMiddleOfGlyph(const SimpleFontData* fontData, Glyph glyph)
517 { 517 {
518 if (fontData->platformData().orientation() == Horizontal) { 518 if (fontData->platformData().orientation() == Horizontal) {
519 FloatRect bounds = fontData->boundsForGlyph(glyph); 519 FloatRect bounds = fontData->boundsForGlyph(glyph);
520 return bounds.x() + bounds.width() / 2; 520 return bounds.x() + bounds.width() / 2;
521 } 521 }
522 // FIXME: Use glyph bounds once they make sense for vertical fonts. 522 // FIXME: Use glyph bounds once they make sense for vertical fonts.
523 return fontData->widthForGlyph(glyph) / 2; 523 return fontData->widthForGlyph(glyph) / 2;
524 } 524 }
525 525
526 inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i) 526 inline static float offsetToMiddleOfGlyphAtIndex(const GlyphBuffer& glyphBuffer, size_t i)
527 { 527 {
528 return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt( i)); 528 return offsetToMiddleOfGlyph(glyphBuffer.fontDataAt(i), glyphBuffer.glyphAt( i));
529 } 529 }
530 530
531 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point) co nst 531 void Font::drawEmphasisMarks(GraphicsContext* context, const TextRun& run, const GlyphBuffer& glyphBuffer, const AtomicString& mark, const FloatPoint& point, co nst FloatRect& textRect) const
532 { 532 {
533 FontCachePurgePreventer purgePreventer; 533 FontCachePurgePreventer purgePreventer;
534 534
535 GlyphData markGlyphData; 535 GlyphData markGlyphData;
536 if (!getEmphasisMarkGlyphData(mark, markGlyphData)) 536 if (!getEmphasisMarkGlyphData(mark, markGlyphData))
537 return; 537 return;
538 538
539 const SimpleFontData* markFontData = markGlyphData.fontData; 539 const SimpleFontData* markFontData = markGlyphData.fontData;
540 ASSERT(markFontData); 540 ASSERT(markFontData);
541 if (!markFontData) 541 if (!markFontData)
542 return; 542 return;
543 543
544 Glyph markGlyph = markGlyphData.glyph; 544 Glyph markGlyph = markGlyphData.glyph;
545 Glyph spaceGlyph = markFontData->spaceGlyph(); 545 Glyph spaceGlyph = markFontData->spaceGlyph();
546 546
547 float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0); 547 float middleOfLastGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, 0);
548 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph( markFontData, markGlyph), point.y()); 548 FloatPoint startPoint(point.x() + middleOfLastGlyph - offsetToMiddleOfGlyph( markFontData, markGlyph), point.y());
549 549
550 GlyphBuffer markBuffer; 550 GlyphBuffer markBuffer;
551 for (int i = 0; i + 1 < glyphBuffer.size(); ++i) { 551 for (int i = 0; i + 1 < glyphBuffer.size(); ++i) {
552 float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1); 552 float middleOfNextGlyph = offsetToMiddleOfGlyphAtIndex(glyphBuffer, i + 1);
553 float advance = glyphBuffer.advanceAt(i) - middleOfLastGlyph + middleOfN extGlyph; 553 float advance = glyphBuffer.advanceAt(i) - middleOfLastGlyph + middleOfN extGlyph;
554 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont Data, advance); 554 markBuffer.add(glyphBuffer.glyphAt(i) ? markGlyph : spaceGlyph, markFont Data, advance);
555 middleOfLastGlyph = middleOfNextGlyph; 555 middleOfLastGlyph = middleOfNextGlyph;
556 } 556 }
557 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa ceGlyph, markFontData, 0); 557 markBuffer.add(glyphBuffer.glyphAt(glyphBuffer.size() - 1) ? markGlyph : spa ceGlyph, markFontData, 0);
558 558
559 drawGlyphBuffer(context, run, markBuffer, startPoint); 559 drawGlyphBuffer(context, run, markBuffer, startPoint, textRect);
560 } 560 }
561 561
562 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, GlyphOverflow* glyphOverflow) const 562 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, GlyphOverflow* glyphOverflow) const
563 { 563 {
564 WidthIterator it(this, run, fallbackFonts, glyphOverflow); 564 WidthIterator it(this, run, fallbackFonts, glyphOverflow);
565 GlyphBuffer glyphBuffer; 565 GlyphBuffer glyphBuffer;
566 it.advance(run.length(), (typesettingFeatures() & (Kerning | Ligatures)) ? & glyphBuffer : 0); 566 it.advance(run.length(), (typesettingFeatures() & (Kerning | Ligatures)) ? & glyphBuffer : 0);
567 567
568 if (glyphOverflow) { 568 if (glyphOverflow) {
569 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent())); 569 glyphOverflow->top = max<int>(glyphOverflow->top, ceilf(-it.minGlyphBoun dingBoxY()) - (glyphOverflow->computeBounds ? 0 : fontMetrics().ascent()));
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (delta <= 0) 631 if (delta <= 0)
632 break; 632 break;
633 } 633 }
634 } 634 }
635 } 635 }
636 636
637 return offset; 637 return offset;
638 } 638 }
639 639
640 } 640 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698