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

Side by Side Diff: Source/platform/fonts/Font.cpp

Issue 860163004: Using FloatRect in SimpleShaper and remove GlyphBounds (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Comment fixes Created 5 years, 11 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
OLDNEW
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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 { 101 {
102 if (codePath(runInfo) == ComplexPath) { 102 if (codePath(runInfo) == ComplexPath) {
103 HarfBuzzShaper shaper(this, runInfo.run, (forTextEmphasis == ForTextEmph asis) 103 HarfBuzzShaper shaper(this, runInfo.run, (forTextEmphasis == ForTextEmph asis)
104 ? HarfBuzzShaper::ForTextEmphasis : HarfBuzzShaper::NotForTextEmphas is); 104 ? HarfBuzzShaper::ForTextEmphasis : HarfBuzzShaper::NotForTextEmphas is);
105 shaper.setDrawRange(runInfo.from, runInfo.to); 105 shaper.setDrawRange(runInfo.from, runInfo.to);
106 shaper.shape(&glyphBuffer); 106 shaper.shape(&glyphBuffer);
107 return shaper.totalWidth(); 107 return shaper.totalWidth();
108 } 108 }
109 109
110 SimpleShaper shaper(this, runInfo.run, nullptr /* fallbackFonts */, 110 SimpleShaper shaper(this, runInfo.run, nullptr /* fallbackFonts */,
111 nullptr /* GlyphBounds */, forTextEmphasis); 111 nullptr, forTextEmphasis);
112 shaper.advance(runInfo.from); 112 shaper.advance(runInfo.from);
113 shaper.advance(runInfo.to, &glyphBuffer); 113 shaper.advance(runInfo.to, &glyphBuffer);
114 float width = shaper.runWidthSoFar(); 114 float width = shaper.runWidthSoFar();
115 115
116 if (runInfo.run.rtl()) { 116 if (runInfo.run.rtl()) {
117 // Glyphs are shaped & stored in RTL advance order - reverse them for LT R drawing. 117 // Glyphs are shaped & stored in RTL advance order - reverse them for LT R drawing.
118 shaper.advance(runInfo.run.length()); 118 shaper.advance(runInfo.run.length());
119 glyphBuffer.reverseForSimpleRTL(width, shaper.runWidthSoFar()); 119 glyphBuffer.reverseForSimpleRTL(width, shaper.runWidthSoFar());
120 } 120 }
121 121
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 if ((textMode & TextModeStroke) && gc->hasStroke()) { 779 if ((textMode & TextModeStroke) && gc->hasStroke()) {
780 SkPaint paint = gc->strokePaint(); 780 SkPaint paint = gc->strokePaint();
781 if (textMode & TextModeFill) 781 if (textMode & TextModeFill)
782 paint.setLooper(0); 782 paint.setLooper(0);
783 gc->drawTextBlob(blob, origin, paint); 783 gc->drawTextBlob(blob, origin, paint);
784 } 784 }
785 } 785 }
786 786
787 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* fallbackFonts, IntRectOutsets* glyphBounds) const 787 float Font::floatWidthForComplexText(const TextRun& run, HashSet<const SimpleFon tData*>* fallbackFonts, IntRectOutsets* glyphBounds) const
788 { 788 {
789 HarfBuzzShaper shaper(this, run, HarfBuzzShaper::NotForTextEmphasis, fallbac kFonts); 789 FloatRect bounds;
790 HarfBuzzShaper shaper(this, run, HarfBuzzShaper::NotForTextEmphasis, fallbac kFonts, glyphBounds ? &bounds : 0);
790 if (!shaper.shape()) 791 if (!shaper.shape())
791 return 0; 792 return 0;
792 793
793 glyphBounds->setTop(ceilf(-shaper.glyphBoundingBox().y())); 794 glyphBounds->setTop(ceilf(-bounds.y()));
794 glyphBounds->setBottom(ceilf(shaper.glyphBoundingBox().maxY())); 795 glyphBounds->setBottom(ceilf(bounds.maxY()));
795 glyphBounds->setLeft(std::max<int>(0, ceilf(-shaper.glyphBoundingBox().x())) ); 796 glyphBounds->setLeft(std::max<int>(0, ceilf(-bounds.x())));
796 glyphBounds->setRight(std::max<int>(0, ceilf(shaper.glyphBoundingBox().maxX( ) - shaper.totalWidth()))); 797 glyphBounds->setRight(std::max<int>(0, ceilf(bounds.maxX() - shaper.totalWid th())));
797 798
798 return shaper.totalWidth(); 799 return shaper.totalWidth();
799 } 800 }
800 801
801 // Return the code point index for the given |x| offset into the text run. 802 // Return the code point index for the given |x| offset into the text run.
802 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat, 803 int Font::offsetForPositionForComplexText(const TextRun& run, float xFloat,
803 bool includePartialGlyphs) const 804 bool includePartialGlyphs) const
804 { 805 {
805 HarfBuzzShaper shaper(this, run); 806 HarfBuzzShaper shaper(this, run);
806 if (!shaper.shape()) 807 if (!shaper.shape())
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 markBuffer.add(markGlyphData.glyph, markFontData, FloatPoint(- offse tToMiddleOfGlyph(markFontData, markGlyphData.glyph), 886 markBuffer.add(markGlyphData.glyph, markFontData, FloatPoint(- offse tToMiddleOfGlyph(markFontData, markGlyphData.glyph),
886 glyphBuffer.xOffsetAt(i) - offsetToMiddleOfGlyph(markFontData, m arkGlyphData.glyph, Vertical))); 887 glyphBuffer.xOffsetAt(i) - offsetToMiddleOfGlyph(markFontData, m arkGlyphData.glyph, Vertical)));
887 } 888 }
888 } 889 }
889 890
890 drawGlyphBuffer(context, runInfo, markBuffer, point); 891 drawGlyphBuffer(context, runInfo, markBuffer, point);
891 } 892 }
892 893
893 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, IntRectOutsets* glyphBounds) const 894 float Font::floatWidthForSimpleText(const TextRun& run, HashSet<const SimpleFont Data*>* fallbackFonts, IntRectOutsets* glyphBounds) const
894 { 895 {
895 SimpleShaper::GlyphBounds bounds; 896 FloatRect bounds;
896 SimpleShaper shaper(this, run, fallbackFonts, glyphBounds ? &bounds : 0); 897 SimpleShaper shaper(this, run, fallbackFonts, glyphBounds ? &bounds : 0);
897 shaper.advance(run.length()); 898 shaper.advance(run.length());
899 float runWidth = shaper.runWidthSoFar();
898 900
899 if (glyphBounds) { 901 if (glyphBounds) {
900 glyphBounds->setTop(ceilf(-bounds.minGlyphBoundingBoxY)); 902 glyphBounds->setTop(ceilf(-bounds.y()));
901 glyphBounds->setBottom(ceilf(bounds.maxGlyphBoundingBoxY)); 903 glyphBounds->setBottom(ceilf(bounds.maxY()));
902 glyphBounds->setLeft(ceilf(bounds.firstGlyphOverflow)); 904 glyphBounds->setLeft(std::max<int>(0, ceilf(-bounds.x())));
903 glyphBounds->setRight(ceilf(bounds.lastGlyphOverflow)); 905 glyphBounds->setRight(std::max<int>(0, ceilf(bounds.maxX() - runWidth))) ;
904 } 906 }
905 907 return runWidth;
906 return shaper.runWidthSoFar();
907 } 908 }
908 909
909 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const 910 FloatRect Font::selectionRectForSimpleText(const TextRun& run, const FloatPoint& point, int h, int from, int to, bool accountForGlyphBounds) const
910 { 911 {
911 SimpleShaper::GlyphBounds bounds; 912 FloatRect bounds;
912 SimpleShaper shaper(this, run, 0, accountForGlyphBounds ? &bounds : 0); 913 SimpleShaper shaper(this, run, 0, accountForGlyphBounds ? &bounds : 0);
913 shaper.advance(from); 914 shaper.advance(from);
914 float fromX = shaper.runWidthSoFar(); 915 float fromX = shaper.runWidthSoFar();
915 shaper.advance(to); 916 shaper.advance(to);
916 float toX = shaper.runWidthSoFar(); 917 float toX = shaper.runWidthSoFar();
917 918
918 if (run.rtl()) { 919 if (run.rtl()) {
919 shaper.advance(run.length()); 920 shaper.advance(run.length());
920 float totalWidth = shaper.runWidthSoFar(); 921 float totalWidth = shaper.runWidthSoFar();
921 float beforeWidth = fromX; 922 float beforeWidth = fromX;
922 float afterWidth = toX; 923 float afterWidth = toX;
923 fromX = totalWidth - afterWidth; 924 fromX = totalWidth - afterWidth;
924 toX = totalWidth - beforeWidth; 925 toX = totalWidth - beforeWidth;
925 } 926 }
926 927
927 return FloatRect(point.x() + fromX, 928 return FloatRect(point.x() + fromX,
928 accountForGlyphBounds ? bounds.minGlyphBoundingBoxY : point.y(), 929 accountForGlyphBounds ? bounds.y(): point.y(),
929 toX - fromX, 930 toX - fromX,
930 accountForGlyphBounds ? bounds.maxGlyphBoundingBoxY - bounds.minGlyphBou ndingBoxY : h); 931 accountForGlyphBounds ? bounds.maxY()- bounds.y(): h);
931 } 932 }
932 933
933 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const 934 int Font::offsetForPositionForSimpleText(const TextRun& run, float x, bool inclu dePartialGlyphs) const
934 { 935 {
935 float delta = x; 936 float delta = x;
936 937
937 SimpleShaper shaper(this, run); 938 SimpleShaper shaper(this, run);
938 unsigned offset; 939 unsigned offset;
939 if (run.rtl()) { 940 if (run.rtl()) {
940 delta -= floatWidthForSimpleText(run); 941 delta -= floatWidthForSimpleText(run);
(...skipping 25 matching lines...) Expand all
966 if (delta <= 0) 967 if (delta <= 0)
967 break; 968 break;
968 } 969 }
969 } 970 }
970 } 971 }
971 972
972 return offset; 973 return offset;
973 } 974 }
974 975
975 } // namespace blink 976 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698