1 /* 2 * Copyright (C) 2007 Rob Buis <buis@kde.org> 3 * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 * 20 */ 21 22 #ifndef SVGInlineTextBox_h 23 #define SVGInlineTextBox_h 24 25 #if ENABLE(SVG) 26 #include "InlineTextBox.h" 27 28 namespace WebCore { 29 30 class SVGRootInlineBox; 31 32 struct SVGChar; 33 struct SVGTextDecorationInfo; 34 35 enum SVGTextPaintSubphase { 36 SVGTextPaintSubphaseBackground, 37 SVGTextPaintSubphaseGlyphFill, 38 SVGTextPaintSubphaseGlyphFillSelection, 39 SVGTextPaintSubphaseGlyphStroke, 40 SVGTextPaintSubphaseGlyphStrokeSelection, 41 SVGTextPaintSubphaseForeground 42 }; 43 44 struct SVGTextPaintInfo { SVGTextPaintInfoSVGTextPaintInfo45 SVGTextPaintInfo() : activePaintServer(0), subphase(SVGTextPaintSubphaseBackground) {} 46 47 SVGPaintServer* activePaintServer; 48 SVGTextPaintSubphase subphase; 49 }; 50 51 class SVGInlineTextBox : public InlineTextBox { 52 public: 53 SVGInlineTextBox(RenderObject* obj); 54 virtualHeight()55 virtual int virtualHeight() const { return m_height; } setHeight(int h)56 void setHeight(int h) { m_height = h; } 57 58 virtual int selectionTop(); 59 virtual int selectionHeight(); 60 61 virtual int offsetForPosition(int x, bool includePartialGlyphs = true) const; 62 virtual int positionForOffset(int offset) const; 63 64 virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, int x, int y, int tx, int ty); 65 virtual IntRect selectionRect(int absx, int absy, int startPos, int endPos); 66 67 // SVGs custom paint text method 68 void paintCharacters(RenderObject::PaintInfo&, int tx, int ty, const SVGChar&, const UChar* chars, int length, SVGTextPaintInfo&); 69 70 // SVGs custom paint selection method 71 void paintSelection(int boxStartOffset, const SVGChar&, const UChar*, int length, GraphicsContext*, RenderStyle*, const Font&); 72 73 // SVGs custom paint decoration method 74 void paintDecoration(ETextDecoration, GraphicsContext*, int tx, int ty, int width, const SVGChar&, const SVGTextDecorationInfo&); 75 76 SVGRootInlineBox* svgRootInlineBox() const; 77 78 // Helper functions shared with SVGRootInlineBox 79 float calculateGlyphWidth(RenderStyle* style, int offset, int extraCharsAvailable, int& charsConsumed, String& glyphName) const; 80 float calculateGlyphHeight(RenderStyle*, int offset, int extraCharsAvailable) const; 81 82 FloatRect calculateGlyphBoundaries(RenderStyle*, int offset, const SVGChar&) const; 83 SVGChar* closestCharacterToPosition(int x, int y, int& offset) const; 84 85 private: 86 friend class RenderSVGInlineText; 87 bool svgCharacterHitsPosition(int x, int y, int& offset) const; 88 bool chunkSelectionStartEnd(const UChar* chunk, int chunkLength, int& selectionStart, int& selectionEnd); 89 90 int m_height; 91 }; 92 93 } // namespace WebCore 94 95 #endif 96 #endif // SVGInlineTextBox_h 97