Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / public / web / WebFont.h
blob412c8c58e8f9d64ffd9c036fdcda38825b92c523
1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef WebFont_h
32 #define WebFont_h
34 #include "../platform/WebCanvas.h"
35 #include "../platform/WebColor.h"
36 #include "../platform/WebCommon.h"
38 namespace blink {
40 struct WebFontDescription;
41 struct WebFloatPoint;
42 struct WebFloatRect;
43 struct WebRect;
44 struct WebTextRun;
46 class WebFont {
47 public:
48 virtual ~WebFont() { }
50 BLINK_EXPORT static WebFont* create(const WebFontDescription&);
52 virtual WebFontDescription fontDescription() const = 0;
54 virtual int ascent() const = 0;
55 virtual int descent() const = 0;
56 virtual int height() const = 0;
57 virtual int lineSpacing() const = 0;
58 virtual float xHeight() const = 0;
60 // Draws the text run to the given canvas. The text is positioned at the
61 // given left-hand point at the baseline.
63 // The text will be clipped to the given clip rect.
64 virtual void drawText(WebCanvas*, const WebTextRun&, const WebFloatPoint& leftBaseline, WebColor,
65 const WebRect& clip) const = 0;
68 // Measures the width in pixels of the given text run.
69 virtual int calculateWidth(const WebTextRun&) const = 0;
71 // Returns the character offset corresponding to the given horizontal pixel
72 // position as measured from from the left of the run.
73 virtual int offsetForPosition(const WebTextRun&, float position) const = 0;
75 // Returns the rectangle representing the selection rect for the subrange
76 // |from| -> |to| of the given text run. You can use -1 for |to| to specify
77 // the entire run (this will do something similar to calling width()).
79 // The rect will be positioned as if the text was drawn at the given
80 // |leftBaseline| position. |height| indicates the height of the selection
81 // rect you want, typically this will just be the height() of this font.
83 // To get the pixel offset of some character (the opposite of
84 // offsetForPosition()), pass in a |leftBaseline| = (0, 0), |from| = 0, and
85 // |to| = the character you want. The right edge of the resulting selection
86 // rect will tell you the right side of the character.
87 virtual WebFloatRect selectionRectForText(const WebTextRun&, const WebFloatPoint& leftBaseline,
88 int height, int from = 0, int to = -1) const = 0;
91 } // namespace blink
93 #endif