| // Copyright 2014 The Cobalt Authors. All Rights Reserved. |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #ifndef COBALT_RENDER_TREE_TEXT_NODE_H_ |
| #define COBALT_RENDER_TREE_TEXT_NODE_H_ |
| |
| #include <string> |
| #include <vector> |
| |
| #include "base/compiler_specific.h" |
| #include "base/memory/ref_counted.h" |
| #include "base/optional.h" |
| #include "base/strings/string_piece.h" |
| #include "cobalt/base/type_id.h" |
| #include "cobalt/math/rect_f.h" |
| #include "cobalt/math/vector2d_f.h" |
| #include "cobalt/render_tree/color_rgba.h" |
| #include "cobalt/render_tree/glyph_buffer.h" |
| #include "cobalt/render_tree/node.h" |
| #include "cobalt/render_tree/shadow.h" |
| |
| namespace cobalt { |
| namespace render_tree { |
| |
| // A single line of text or a directional run as specified by Unicode |
| // Bidirectional Algorithm (http://www.unicode.org/reports/tr9/). |
| // When rendering the text node, the origin will horizontally be on the far left |
| // of the text, and vertically it will be on the text's baseline. This means |
| // that the text bounding box may cover area above and below the TextNode's |
| // origin. |
| class TextNode : public Node { |
| public: |
| struct Builder { |
| Builder(const Builder&) = default; |
| Builder(const math::Vector2dF& offset, |
| const scoped_refptr<GlyphBuffer>& glyph_buffer, |
| const ColorRGBA& color); |
| |
| bool operator==(const Builder& other) const { |
| return offset == other.offset && glyph_buffer == other.glyph_buffer && |
| color == other.color && shadows == other.shadows; |
| } |
| |
| math::Vector2dF offset; |
| |
| // All of the glyph data needed to render the text. |
| scoped_refptr<GlyphBuffer> glyph_buffer; |
| |
| // The foreground color of the text. |
| ColorRGBA color; |
| |
| // Shadows to be applied under the text. These will be drawn in |
| // back-to-front order, so the last shadow will be on the bottom. |
| base::Optional<std::vector<Shadow> > shadows; |
| }; |
| |
| // Forwarding constructor to the set of Builder constructors. |
| template <typename... Args> |
| TextNode(Args&&... args) : data_(std::forward<Args>(args)...) {} |
| |
| void Accept(NodeVisitor* visitor) override; |
| math::RectF GetBounds() const override; |
| |
| base::TypeId GetTypeId() const override { |
| return base::GetTypeId<TextNode>(); |
| } |
| |
| const Builder& data() const { return data_; } |
| |
| private: |
| const Builder data_; |
| }; |
| |
| } // namespace render_tree |
| } // namespace cobalt |
| |
| #endif // COBALT_RENDER_TREE_TEXT_NODE_H_ |