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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 return 0; | 630 return 0; |
631 | 631 |
632 const SimpleFontData* markFontData = markGlyphData.fontData; | 632 const SimpleFontData* markFontData = markGlyphData.fontData; |
633 ASSERT(markFontData); | 633 ASSERT(markFontData); |
634 if (!markFontData) | 634 if (!markFontData) |
635 return 0; | 635 return 0; |
636 | 636 |
637 return markFontData->fontMetrics().height(); | 637 return markFontData->fontMetrics().height(); |
638 } | 638 } |
639 | 639 |
640 void Font::paintGlyphs(SkCanvas* canvas, const SkPaint& paint, const SimpleFontD
ata* font, | |
641 const Glyph glyphs[], unsigned numGlyphs, | |
642 const SkPoint pos[], const FloatRect& textRect, float deviceScaleFactor) con
st | |
643 { | |
644 SkPaint fontPaint(paint); | |
645 font->platformData().setupPaint(&fontPaint, deviceScaleFactor, this); | |
646 fontPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
647 canvas->drawPosText(glyphs, numGlyphs * sizeof(Glyph), pos, fontPaint); | |
648 } | |
649 | |
650 void Font::paintGlyphsHorizontal(SkCanvas* canvas, const SkPaint& paint, const S
impleFontData* font, | |
651 const Glyph glyphs[], unsigned numGlyphs, | |
652 const SkScalar xpos[], SkScalar constY, const FloatRect& textRect, float dev
iceScaleFactor) const | |
653 { | |
654 SkPaint fontPaint(paint); | |
655 font->platformData().setupPaint(&fontPaint, deviceScaleFactor, this); | |
656 fontPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | |
657 canvas->drawPosTextH(glyphs, numGlyphs * sizeof(Glyph), xpos, constY, fontPa
int); | |
658 } | |
659 | |
660 void Font::drawGlyphs(SkCanvas* canvas, const SkPaint& paint, const SimpleFontDa
ta* font, | 640 void Font::drawGlyphs(SkCanvas* canvas, const SkPaint& paint, const SimpleFontDa
ta* font, |
661 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, | 641 const GlyphBuffer& glyphBuffer, unsigned from, unsigned numGlyphs, |
662 const FloatPoint& point, const FloatRect& textRect, float deviceScaleFactor)
const | 642 const FloatPoint& point, float deviceScaleFactor) const |
663 { | 643 { |
664 ASSERT(glyphBuffer.size() >= from + numGlyphs); | 644 ASSERT(glyphBuffer.size() >= from + numGlyphs); |
665 | 645 |
666 if (!glyphBuffer.hasVerticalOffsets()) { | 646 // We only ever reach this fallback code path when failing to build a text b
lob due to |
667 Vector<SkScalar, 64> xpos(numGlyphs); | 647 // verticalAnyUpright text in the buffer => the buffer is guaranteed to stor
e vertical offsets. |
668 for (unsigned i = 0; i < numGlyphs; i++) | 648 ASSERT(glyphBuffer.hasVerticalOffsets()); |
669 xpos[i] = SkFloatToScalar(point.x() + glyphBuffer.xOffsetAt(from + i
)); | |
670 | |
671 paintGlyphsHorizontal(canvas, paint, font, glyphBuffer.glyphs(from), num
Glyphs, xpos.data(), | |
672 SkFloatToScalar(point.y()), textRect, deviceScaleFactor); | |
673 return; | |
674 } | |
675 | 649 |
676 bool drawVertically = font->platformData().isVerticalAnyUpright() && font->v
erticalData(); | 650 bool drawVertically = font->platformData().isVerticalAnyUpright() && font->v
erticalData(); |
677 | 651 |
678 int canvasStackLevel = canvas->getSaveCount(); | 652 SkAutoCanvasRestore autoRestore(canvas, false); |
679 if (drawVertically) { | 653 if (drawVertically) { |
680 canvas->save(); | 654 canvas->save(); |
681 canvas->concat(affineTransformToSkMatrix(AffineTransform(0, -1, 1, 0, po
int.x(), point.y()))); | 655 canvas->concat(affineTransformToSkMatrix(AffineTransform(0, -1, 1, 0, po
int.x(), point.y()))); |
682 canvas->concat(affineTransformToSkMatrix(AffineTransform(1, 0, 0, 1, -po
int.x(), -point.y()))); | 656 canvas->concat(affineTransformToSkMatrix(AffineTransform(1, 0, 0, 1, -po
int.x(), -point.y()))); |
683 } | 657 } |
684 | 658 |
685 const float verticalBaselineXOffset = drawVertically ? SkFloatToScalar(font-
>fontMetrics().floatAscent() - font->fontMetrics().floatAscent(IdeographicBaseli
ne)) : 0; | 659 const float verticalBaselineXOffset = drawVertically ? SkFloatToScalar(font-
>fontMetrics().floatAscent() - font->fontMetrics().floatAscent(IdeographicBaseli
ne)) : 0; |
686 | 660 |
687 ASSERT(glyphBuffer.hasVerticalOffsets()); | |
688 Vector<SkPoint, 32> pos(numGlyphs); | 661 Vector<SkPoint, 32> pos(numGlyphs); |
689 for (unsigned i = 0; i < numGlyphs; i++) { | 662 for (unsigned i = 0; i < numGlyphs; i++) { |
690 pos[i].set( | 663 pos[i].set( |
691 SkFloatToScalar(point.x() + verticalBaselineXOffset + glyphBuffer.xO
ffsetAt(from + i)), | 664 SkFloatToScalar(point.x() + verticalBaselineXOffset + glyphBuffer.xO
ffsetAt(from + i)), |
692 SkFloatToScalar(point.y() + glyphBuffer.yOffsetAt(from + i))); | 665 SkFloatToScalar(point.y() + glyphBuffer.yOffsetAt(from + i))); |
693 } | 666 } |
694 | 667 |
695 paintGlyphs(canvas, paint, font, glyphBuffer.glyphs(from), numGlyphs, pos.da
ta(), textRect, deviceScaleFactor); | 668 SkPaint fontPaint(paint); |
696 canvas->restoreToCount(canvasStackLevel); | 669 font->platformData().setupPaint(&fontPaint, deviceScaleFactor, this); |
| 670 fontPaint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| 671 canvas->drawPosText(glyphBuffer.glyphs(from), numGlyphs * sizeof(Glyph), pos
.data(), fontPaint); |
697 } | 672 } |
698 | 673 |
699 void Font::drawTextBlob(SkCanvas* canvas, const SkPaint& paint, const SkTextBlob
* blob, const SkPoint& origin) const | 674 void Font::drawTextBlob(SkCanvas* canvas, const SkPaint& paint, const SkTextBlob
* blob, const SkPoint& origin) const |
700 { | 675 { |
701 canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); | 676 canvas->drawTextBlob(blob, origin.x(), origin.y(), paint); |
702 } | 677 } |
703 | 678 |
704 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon
tData*>* fallbackFonts, FloatRect* glyphBounds) const | 679 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon
tData*>* fallbackFonts, FloatRect* glyphBounds) const |
705 { | 680 { |
706 CachingWordShaper shaper(m_fontFallbackList->shapeCache(m_fontDescription)); | 681 CachingWordShaper shaper(m_fontFallbackList->shapeCache(m_fontDescription)); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 | 715 |
741 // Draw each contiguous run of glyphs that use the same font data. | 716 // Draw each contiguous run of glyphs that use the same font data. |
742 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); | 717 const SimpleFontData* fontData = glyphBuffer.fontDataAt(0); |
743 unsigned lastFrom = 0; | 718 unsigned lastFrom = 0; |
744 unsigned nextGlyph; | 719 unsigned nextGlyph; |
745 | 720 |
746 for (nextGlyph = 0; nextGlyph < glyphBuffer.size(); ++nextGlyph) { | 721 for (nextGlyph = 0; nextGlyph < glyphBuffer.size(); ++nextGlyph) { |
747 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); | 722 const SimpleFontData* nextFontData = glyphBuffer.fontDataAt(nextGlyph); |
748 | 723 |
749 if (nextFontData != fontData) { | 724 if (nextFontData != fontData) { |
750 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph
- lastFrom, point, runInfo.bounds, deviceScaleFactor); | 725 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph
- lastFrom, point, deviceScaleFactor); |
751 lastFrom = nextGlyph; | 726 lastFrom = nextGlyph; |
752 fontData = nextFontData; | 727 fontData = nextFontData; |
753 } | 728 } |
754 } | 729 } |
755 | 730 |
756 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastF
rom, point, runInfo.bounds, deviceScaleFactor); | 731 drawGlyphs(canvas, paint, fontData, glyphBuffer, lastFrom, nextGlyph - lastF
rom, point, deviceScaleFactor); |
757 } | 732 } |
758 | 733 |
759 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
Data*>* fallbackFonts, FloatRect* glyphBounds) const | 734 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont
Data*>* fallbackFonts, FloatRect* glyphBounds) const |
760 { | 735 { |
761 SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds); | 736 SimpleShaper shaper(this, run, nullptr, fallbackFonts, glyphBounds); |
762 shaper.advance(run.length()); | 737 shaper.advance(run.length()); |
763 return shaper.runWidthSoFar(); | 738 return shaper.runWidthSoFar(); |
764 } | 739 } |
765 | 740 |
766 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
point, int h, int from, int to, bool accountForGlyphBounds) const | 741 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint&
point, int h, int from, int to, bool accountForGlyphBounds) const |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 { | 808 { |
834 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); | 809 return m_fontFallbackList && m_fontFallbackList->loadingCustomFonts(); |
835 } | 810 } |
836 | 811 |
837 bool Font::isFallbackValid() const | 812 bool Font::isFallbackValid() const |
838 { | 813 { |
839 return !m_fontFallbackList || m_fontFallbackList->isValid(); | 814 return !m_fontFallbackList || m_fontFallbackList->isValid(); |
840 } | 815 } |
841 | 816 |
842 } // namespace blink | 817 } // namespace blink |
OLD | NEW |