LayoutInlineBoxText.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_CORE_LAYOUTINLINEBOXTEXT_H
  29. #define RMLUI_CORE_LAYOUTINLINEBOXTEXT_H
  30. #include "LayoutInlineBox.h"
  31. namespace Rml {
  32. /**
  33. @author Peter Curry
  34. */
  35. class LayoutInlineBoxText : public LayoutInlineBox
  36. {
  37. public:
  38. /// Constructs a new inline box for a text element.
  39. /// @param[in] element The text element this inline box is flowing.
  40. /// @param[in] line_begin The index of the first character of the element's string this text box will render.
  41. LayoutInlineBoxText(ElementText* element, int line_begin = 0);
  42. virtual ~LayoutInlineBoxText();
  43. /// Returns true if this box is capable of overflowing, or if it must be rendered on a single line.
  44. /// @return True if this box can overflow, false otherwise.
  45. bool CanOverflow() const override;
  46. /// Flows the inline box's content into its parent line.
  47. /// @param[in] first_box True if this box is the first box containing content to be flowed into this line.
  48. /// @param available_width[in] The width available for flowing this box's content. This is measured from the left side of this box's content area.
  49. /// @param right_spacing_width[in] The width of the spacing that must be left on the right of the element if no overflow occurs. If overflow occurs, then the entire width can be used.
  50. /// @return The overflow box containing any content that spilled over from the flow. This must be nullptr if no overflow occured.
  51. UniquePtr<LayoutInlineBox> FlowContent(bool first_box, float available_width, float right_spacing_width) override;
  52. /// Computes and sets the vertical position of this element, relative to its parent inline box (or block box,
  53. /// for an un-nested inline box).
  54. /// @param ascender[out] The maximum ascender of this inline box and all of its children.
  55. /// @param descender[out] The maximum descender of this inline box and all of its children.
  56. void CalculateBaseline(float& ascender, float& descender) override;
  57. /// Offsets the baseline of this box, and all of its children, by the ascender of the parent line box.
  58. /// @param ascender[in] The ascender of the line box.
  59. void OffsetBaseline(float ascender) override;
  60. /// Positions the inline box's element.
  61. void PositionElement() override;
  62. /// Sizes the inline box's element.
  63. void SizeElement(bool split) override;
  64. void* operator new(size_t size);
  65. void operator delete(void* chunk, size_t size);
  66. private:
  67. /// Returns the box's element as a text element.
  68. /// @return The box's element cast to a text element.
  69. ElementText* GetTextElement();
  70. /// Builds a box for the first word of the element.
  71. void BuildWordBox();
  72. // The index of the first character of this line.
  73. int line_begin;
  74. // The contents on this line.
  75. String line_contents;
  76. // True if this line can be segmented into parts, false if it consists of only a single word.
  77. bool line_segmented;
  78. };
  79. String FontFaceDescription(const String& font_family, Style::FontStyle style, Style::FontWeight weight);
  80. } // namespace Rml
  81. #endif