Add/resurrect support for bundles of WebStore items.
[chromium-blink-merge.git] / ppapi / cpp / dev / font_dev.h
blobd0875a50cc3fe599bb7a388f7a950c8f7d1bd5c8
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_CPP_DEV_FONT_DEV_H_
6 #define PPAPI_CPP_DEV_FONT_DEV_H_
8 #include <string>
10 #include "ppapi/c/dev/ppb_font_dev.h"
11 #include "ppapi/cpp/resource.h"
12 #include "ppapi/cpp/var.h"
14 struct PP_FontDescription_Dev;
16 namespace pp {
18 class ImageData;
19 class InstanceHandle;
20 class Point;
21 class Rect;
23 // FontDescription_Dev ---------------------------------------------------------
25 class FontDescription_Dev {
26 public:
27 FontDescription_Dev();
28 FontDescription_Dev(const FontDescription_Dev& other);
29 ~FontDescription_Dev();
31 FontDescription_Dev& operator=(const FontDescription_Dev& other);
33 const PP_FontDescription_Dev& pp_font_description() const {
34 return pp_font_description_;
37 Var face() const { return face_; }
38 void set_face(const Var& face) {
39 face_ = face;
40 pp_font_description_.face = face_.pp_var();
43 PP_FontFamily_Dev family() const { return pp_font_description_.family; }
44 void set_family(PP_FontFamily_Dev f) { pp_font_description_.family = f; }
46 uint32_t size() const { return pp_font_description_.size; }
47 void set_size(uint32_t s) { pp_font_description_.size = s; }
49 PP_FontWeight_Dev weight() const { return pp_font_description_.weight; }
50 void set_weight(PP_FontWeight_Dev w) { pp_font_description_.weight = w; }
52 bool italic() const { return PP_ToBool(pp_font_description_.italic); }
53 void set_italic(bool i) { pp_font_description_.italic = PP_FromBool(i); }
55 bool small_caps() const {
56 return PP_ToBool(pp_font_description_.small_caps);
58 void set_small_caps(bool s) {
59 pp_font_description_.small_caps = PP_FromBool(s);
62 int letter_spacing() const { return pp_font_description_.letter_spacing; }
63 void set_letter_spacing(int s) { pp_font_description_.letter_spacing = s; }
65 int word_spacing() const { return pp_font_description_.word_spacing; }
66 void set_word_spacing(int w) { pp_font_description_.word_spacing = w; }
68 private:
69 friend class Font_Dev;
71 Var face_; // Manages memory for pp_font_description_.face
72 PP_FontDescription_Dev pp_font_description_;
75 // TextRun_Dev -----------------------------------------------------------------
77 class TextRun_Dev {
78 public:
79 TextRun_Dev();
80 TextRun_Dev(const std::string& text,
81 bool rtl = false,
82 bool override_direction = false);
83 TextRun_Dev(const TextRun_Dev& other);
84 ~TextRun_Dev();
86 TextRun_Dev& operator=(const TextRun_Dev& other);
88 const PP_TextRun_Dev& pp_text_run() const {
89 return pp_text_run_;
92 private:
93 Var text_; // Manages memory for the reference in pp_text_run_.
94 PP_TextRun_Dev pp_text_run_;
97 // Font ------------------------------------------------------------------------
99 // Provides access to system fonts.
100 class Font_Dev : public Resource {
101 public:
102 // Creates an is_null() Font object.
103 Font_Dev();
105 explicit Font_Dev(PP_Resource resource);
106 Font_Dev(const InstanceHandle& instance,
107 const FontDescription_Dev& description);
108 Font_Dev(const Font_Dev& other);
110 Font_Dev& operator=(const Font_Dev& other);
112 // PPB_Font methods:
113 static Var GetFontFamilies(const InstanceHandle& instance);
114 bool Describe(FontDescription_Dev* description,
115 PP_FontMetrics_Dev* metrics) const;
116 bool DrawTextAt(ImageData* dest,
117 const TextRun_Dev& text,
118 const Point& position,
119 uint32_t color,
120 const Rect& clip,
121 bool image_data_is_opaque) const;
122 int32_t MeasureText(const TextRun_Dev& text) const;
123 uint32_t CharacterOffsetForPixel(const TextRun_Dev& text,
124 int32_t pixel_position) const;
125 int32_t PixelOffsetForCharacter(const TextRun_Dev& text,
126 uint32_t char_offset) const;
128 // Convenience function that assumes a left-to-right string with no clipping.
129 bool DrawSimpleText(ImageData* dest,
130 const std::string& text,
131 const Point& position,
132 uint32_t color,
133 bool image_data_is_opaque = false) const;
135 // Convenience function that assumes a left-to-right string.
136 int32_t MeasureSimpleText(const std::string& text) const;
139 } // namespace pp
141 #endif // PPAPI_CPP_DEV_FONT_DEV_H_