1/*
2 * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>
3 * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2008 Rob Buis <buis@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "FontCascade.h"
25#include "RenderText.h"
26#include "SVGTextLayoutAttributes.h"
27#include "Text.h"
28
29namespace WebCore {
30
31class SVGInlineTextBox;
32
33class RenderSVGInlineText final : public RenderText {
34 WTF_MAKE_ISO_ALLOCATED(RenderSVGInlineText);
35public:
36 RenderSVGInlineText(Text&, const String&);
37
38 Text& textNode() const { return downcast<Text>(nodeForNonAnonymous()); }
39
40 bool characterStartsNewTextChunk(int position) const;
41 SVGTextLayoutAttributes* layoutAttributes() { return &m_layoutAttributes; }
42
43 float scalingFactor() const { return m_scalingFactor; }
44 const FontCascade& scaledFont() const { return m_scaledFont; }
45 void updateScaledFont();
46 static void computeNewScaledFontForStyle(const RenderObject&, const RenderStyle&, float& scalingFactor, FontCascade& scaledFont);
47
48 // Preserves floating point precision for the use in DRT. It knows how to round and does a better job than enclosingIntRect.
49 FloatRect floatLinesBoundingBox() const;
50
51private:
52 const char* renderName() const override { return "RenderSVGInlineText"; }
53
54 String originalText() const override;
55 void setRenderedText(const String&) override;
56 void styleDidChange(StyleDifference, const RenderStyle*) override;
57
58 FloatRect objectBoundingBox() const override { return floatLinesBoundingBox(); }
59
60 bool isSVGInlineText() const override { return true; }
61
62 VisiblePosition positionForPoint(const LayoutPoint&, const RenderFragmentContainer*) override;
63 LayoutRect localCaretRect(InlineBox*, unsigned caretOffset, LayoutUnit* extraWidthToEndOfLine = 0) override;
64 IntRect linesBoundingBox() const override;
65 std::unique_ptr<InlineTextBox> createTextBox() override;
66
67 float m_scalingFactor;
68 FontCascade m_scaledFont;
69 SVGTextLayoutAttributes m_layoutAttributes;
70};
71
72} // namespace WebCore
73
74SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderSVGInlineText, isSVGInlineText())
75