diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-11-09 17:40:13 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:46:45 +0300 |
commit | bcc94857d7b9f092148dea4a2a9b90c592f43a75 (patch) | |
tree | 7bf4c63e9b28fd0b00dfdcffcada9bb2c637b935 /graphics/text_element.cpp | |
parent | 771f47410fa67f271cf425a2b1a9a0ed6119b4ea (diff) |
renamed yg into graphics.
Diffstat (limited to 'graphics/text_element.cpp')
-rw-r--r-- | graphics/text_element.cpp | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/graphics/text_element.cpp b/graphics/text_element.cpp new file mode 100644 index 0000000000..32c0dda9ad --- /dev/null +++ b/graphics/text_element.cpp @@ -0,0 +1,134 @@ +#include "text_element.hpp" +#include "screen.hpp" +#include "skin.hpp" +#include "skin_page.hpp" +#include "resource_manager.hpp" +#include "overlay_renderer.hpp" +#include "resource_style.hpp" + +#include "../base/logging.hpp" + +namespace graphics +{ + TextElement::TextElement(Params const & p) + : OverlayElement(p), + m_fontDesc(p.m_fontDesc), + m_auxFontDesc(p.m_auxFontDesc), + m_logText(p.m_logText), + m_auxLogText(p.m_auxLogText), + m_log2vis(p.m_log2vis) + { + if (m_log2vis) + { + m_visText = p.m_glyphCache->log2vis(m_logText); + if (!m_auxLogText.empty()) + m_auxVisText = p.m_glyphCache->log2vis(m_auxLogText); + } + else + { + m_visText = m_logText; + m_auxVisText = m_auxLogText; + } + } + + strings::UniString const & TextElement::logText() const + { + return m_logText; + } + + strings::UniString const & TextElement::auxLogText() const + { + return m_auxLogText; + } + + strings::UniString const & TextElement::visText() const + { + return m_visText; + } + + strings::UniString const & TextElement::auxVisText() const + { + return m_auxVisText; + } + + FontDesc const & TextElement::fontDesc() const + { + return m_fontDesc; + } + + FontDesc const & TextElement::auxFontDesc() const + { + return m_auxFontDesc; + } + + bool TextElement::isBidi() const + { + return m_logText != m_visText; + } + + bool TextElement::isAuxBidi() const + { + return m_auxLogText != m_auxVisText; + } + + void TextElement::drawTextImpl(GlyphLayout const & layout, + gl::OverlayRenderer * screen, + math::Matrix<double, 3, 3> const & m, + bool doTransformPivotOnly, + bool doAlignPivot, + FontDesc const & fontDesc, + double depth) const + { + if (!fontDesc.IsValid()) + return; + + m2::PointD pv = layout.pivot(); + m2::PointD offs = layout.offset(); + double deltaA = 0; + + if (doTransformPivotOnly) + pv *= m; + else + { + double k = (sqrt((m(0, 0) * m(0, 0) + m(0, 1) * m(0, 1) + m(1, 0) * m(1, 0) + m(1, 1) * m(1, 1)) / 2)); + + if ((k > 1.1) || (k < 1 / 1.1)) + return; + + deltaA = (ang::AngleD(0) * m).val(); + } + + for (unsigned i = layout.firstVisible(); i < layout.lastVisible(); ++i) + { + Skin * skin = screen->skin().get(); + GlyphLayoutElem const & elem = layout.entries()[i]; + GlyphKey glyphKey(elem.m_sym, + fontDesc.m_size, + fontDesc.m_isMasked, + fontDesc.m_isMasked ? fontDesc.m_maskColor : fontDesc.m_color); + uint32_t const glyphID = skin->mapGlyph(glyphKey, screen->glyphCache()); + GlyphStyle const * glyphStyle = static_cast<GlyphStyle const *>(skin->fromID(glyphID)); + + m2::PointD glyphPt; + ang::AngleD glyphAngle; + + if (doTransformPivotOnly) + { + m2::PointD offsPt = offs + elem.m_pt; + m2::PointD fullPt = pv + offs + elem.m_pt; + + offsPt.x -= fullPt.x - floor(fullPt.x); + offsPt.y -= fullPt.y - floor(fullPt.y); + + screen->drawStraightGlyph(pv, offsPt, glyphStyle, depth); + } + else + { + glyphPt = (pv + offs + elem.m_pt) * m; + glyphAngle = ang::AngleD(elem.m_angle.val() + deltaA); + + screen->drawGlyph(glyphPt, m2::PointD(0.0, 0.0), glyphAngle, 0, glyphStyle, depth); + } + } + } +} |