Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Sorokin <sorok-roma@yandex.ru>2014-09-10 11:58:48 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:27:00 +0300
commite6d20c1822c4aaf7f5d6c3c065ef98e21e1d84b0 (patch)
treeecb1b90b8c2642c773d2b3727037df3224438ba3 /drape_frontend
parent452fde5f265e30cac0f2f24da3dafce0c48af613 (diff)
Updated LayoutText
Diffstat (limited to 'drape_frontend')
-rw-r--r--drape_frontend/text_layout.cpp87
-rw-r--r--drape_frontend/text_layout.hpp16
2 files changed, 102 insertions, 1 deletions
diff --git a/drape_frontend/text_layout.cpp b/drape_frontend/text_layout.cpp
index 837cf9ea62..289e086934 100644
--- a/drape_frontend/text_layout.cpp
+++ b/drape_frontend/text_layout.cpp
@@ -88,6 +88,73 @@ TextLayout::TextLayout(strings::UniString const & string,
#endif
}
+dp::OverlayHandle * LayoutText(const FeatureID & featureID,
+ m2::PointF const & pivot,
+ vector<m2::PointF> const & pixelOffset,
+ float depth,
+ vector<Quad4> & positions,
+ vector<Quad4> & texCoord,
+ vector<Quad4> & fontColor,
+ vector<Quad4> & outlineColor,
+ TextLayout * layouts)
+{
+ STATIC_ASSERT(sizeof(vec4) == 4 * sizeof(float));
+ STATIC_ASSERT(sizeof(Quad4) == 4 * sizeof(vec4));
+
+ FillColor(fontColor, layouts[0].GetColor());
+ FillColor(outlineColor,layouts[0].GetOutlineColor());
+
+ int counter = 0;
+ m2::PointD size(0.0, 0.0);
+ m2::PointF offset(numeric_limits<float>::max(), numeric_limits<float>::max());
+ float maxOffset = -numeric_limits<float>::max();
+ for (int j = 0; j < pixelOffset.size(); ++j)
+ {
+ float glyphOffset = 0.0;
+ float textRatio = layouts[j].GetTextRatio();
+ float maxHeight = 0.0f;
+ float minHeight = numeric_limits<float>::max();
+ uint32_t glyphCount = layouts[j].GetGlyphCount();
+ double w;
+ for (size_t i = 0; i < glyphCount; ++i)
+ {
+ dp::TextureSetHolder::GlyphRegion const & region = layouts[j].GetGlyphRegion(i);
+ ASSERT(region.IsValid(), ());
+ layouts[j].GetTextureQuad(region, depth, texCoord[counter]);
+
+ float xOffset, yOffset, advance;
+ region.GetMetrics(xOffset, yOffset, advance);
+
+ xOffset *= textRatio;
+ yOffset *= textRatio;
+ advance *= textRatio;
+
+ m2::PointU size;
+ region.GetPixelSize(size);
+ double const h = size.y * textRatio;
+ w = size.x * textRatio;
+ maxHeight = max((float)h, maxHeight);
+ minHeight = min(yOffset, minHeight);
+
+ Quad4 & position = positions[counter++];
+ position.v[0] = vec4(pivot, m2::PointF(glyphOffset + xOffset, yOffset) + pixelOffset[j]);
+ position.v[1] = vec4(pivot, m2::PointF(glyphOffset + xOffset, yOffset + h) + pixelOffset[j]);
+ position.v[2] = vec4(pivot, m2::PointF(glyphOffset + w + xOffset, yOffset) + pixelOffset[j]);
+ position.v[3] = vec4(pivot, m2::PointF(glyphOffset + w + xOffset, yOffset + h) + pixelOffset[j]);
+ glyphOffset += advance;
+ }
+ glyphOffset += w / 2.0f;
+ size.x = max(size.x, (double)glyphOffset);
+ offset.x = min(offset.x, pixelOffset[j].x);
+ offset.y = min(offset.y, pixelOffset[j].y + minHeight);
+ maxOffset = max(maxOffset, pixelOffset[j].y + minHeight);
+ size.y = max(size.y, (double)maxHeight);
+ }
+ size.y += maxOffset - offset.y;
+ return new StraightTextHandle(featureID, pivot, size, offset, depth);
+}
+
+
dp::OverlayHandle * TextLayout::LayoutText(const FeatureID & featureID,
m2::PointF const & pivot,
m2::PointF const & pixelOffset,
@@ -248,6 +315,26 @@ float TextLayout::GetPixelHeight() const
return m_font.m_size;
}
+dp::Color TextLayout::GetColor() const
+{
+ return m_font.m_color;
+}
+
+dp::Color TextLayout::GetOutlineColor() const
+{
+ return m_font.m_outlineColor;
+}
+
+dp::TextureSetHolder::GlyphRegion & TextLayout::GetGlyphRegion(int index)
+{
+ return m_metrics[index];
+}
+
+float TextLayout::GetTextRatio() const
+{
+ return m_textSizeRatio;
+}
+
void TextLayout::GetTextureQuad(GlyphRegion const & region,
float depth,
Quad4 & quad) const
diff --git a/drape_frontend/text_layout.hpp b/drape_frontend/text_layout.hpp
index 8fa1888e8c..88977bd9c9 100644
--- a/drape_frontend/text_layout.hpp
+++ b/drape_frontend/text_layout.hpp
@@ -51,15 +51,19 @@ public:
uint32_t GetTextureSet() const;
float GetPixelLength() const;
float GetPixelHeight() const;
+ float GetTextRatio() const;
+ dp::Color GetColor() const;
+ dp::Color GetOutlineColor() const;
+ GlyphRegion & GetGlyphRegion(int index);
private:
- void GetTextureQuad(GlyphRegion const & region, float depth, glsl_types::Quad4 & quad) const;
float AccumulateAdvance(double const & currentValue, GlyphRegion const & reg2) const;
void InitMetric(strings::UniChar const & unicodePoint, dp::RefPointer<dp::TextureSetHolder> textures);
public:
void GetMetrics(int32_t const index, float & xOffset, float & yOffset, float & advance,
float & halfWidth, float & halfHeight) const;
+ void GetTextureQuad(GlyphRegion const & region, float depth, glsl_types::Quad4 & quad) const;
private:
buffer_vector<GlyphRegion, 32> m_metrics;
@@ -67,6 +71,16 @@ private:
float m_textSizeRatio;
};
+dp::OverlayHandle * LayoutText(const FeatureID & featureID,
+ m2::PointF const & pivot,
+ vector<m2::PointF> const & pixelOffset,
+ float depth,
+ vector<glsl_types::Quad4> & positions,
+ vector<glsl_types::Quad4> & texCoord,
+ vector<glsl_types::Quad4> & fontColor,
+ vector<glsl_types::Quad4> & outlineColor,
+ TextLayout * layouts);
+
class SharedTextLayout
{
public: