diff --git a/map/drawer_yg.cpp b/map/drawer_yg.cpp index 734434a3a0..056226c103 100644 --- a/map/drawer_yg.cpp +++ b/map/drawer_yg.cpp @@ -246,7 +246,7 @@ void DrawerYG::drawText(m2::PointD const & pt, di::DrawInfo const * pInfo, rule_ // bool isMasked = pRule->GetColor() != -1; bool isMasked = true; - yg::FontDesc fontDesc(false, get_text_font_size(pRule), textColor, isMasked, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(get_text_font_size(pRule), textColor, isMasked, yg::Color(255, 255, 255, 255)); fontDesc.SetRank(pInfo->m_rank); if (!filter_text_size(pRule)) @@ -264,7 +264,7 @@ bool DrawerYG::drawPathText(di::PathInfo const & info, string const & name, uint { // bool const isMasked = (double(fontSize) / m_visualScale >= min_text_height); - yg::FontDesc fontDesc(false, fontSize); + yg::FontDesc fontDesc(fontSize); return m_pScreen->drawPathText( fontDesc, &info.m_path[0], @@ -290,7 +290,6 @@ void DrawerYG::drawPathNumber(di::PathInfo const & path, di::DrawInfo const * pI if (path.GetSmPoint(double(j) / double(count), pt)) { yg::FontDesc fontDesc( - false, textHeight, yg::Color(150, 75, 0, 255), // brown true, diff --git a/map/framework.cpp b/map/framework.cpp index 5a28eb2359..d150f50193 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -787,7 +787,7 @@ void FrameWork::AddRedrawCommandSure() int scaleLevel ) { - fwork::DrawProcessor doDraw(selectRect, screen, e, scaleLevel, m_renderQueue.renderStatePtr(), m_resourceManager->getGlyphCache()); + fwork::DrawProcessor doDraw(selectRect, screen, e, scaleLevel, m_renderQueue.renderStatePtr(), e->drawer()->screen()->glyphCache()); m_renderQueue.renderStatePtr()->m_isEmptyModelCurrent = true; try diff --git a/map/information_display.cpp b/map/information_display.cpp index 7fdee898af..ab62cd9b31 100644 --- a/map/information_display.cpp +++ b/map/information_display.cpp @@ -31,8 +31,8 @@ InformationDisplay::InformationDisplay() for (int i = 0; i < sizeof(m_DebugPts) / sizeof(m2::PointD); ++i) m_DebugPts[i] = m2::PointD(0, 0); - m_fontDesc = yg::FontDesc(false, 12); - m_emptyMessageFont = yg::FontDesc(false, 14); + m_fontDesc = yg::FontDesc(12); + m_emptyMessageFont = yg::FontDesc(14); } void InformationDisplay::setScreen(ScreenBase const & screen) @@ -220,8 +220,7 @@ void InformationDisplay::drawCenter(DrawerYG * drawer) params.m_pivot = m2::PointD(m_displayRect.maxX() - 10 * m_visualScale, m_displayRect.maxY() - (m_bottomShift + 10) * m_visualScale - 5); params.m_position = yg::EPosAboveLeft; - params.m_rm = drawer->screen()->resourceManager().get(); - params.m_skin = drawer->screen()->skin().get(); + params.m_glyphCache = drawer->screen()->glyphCache(); params.m_logText = strings::MakeUniString(out.str()); yg::StraightTextElement ste(params); @@ -389,8 +388,7 @@ void InformationDisplay::drawLog(DrawerYG * drawer) params.m_log2vis = false; params.m_pivot = startPt; params.m_position = yg::EPosAboveRight; - params.m_rm = drawer->screen()->resourceManager().get(); - params.m_skin = drawer->screen()->skin().get(); + params.m_glyphCache = drawer->screen()->glyphCache(); params.m_logText = strings::MakeUniString(*it); yg::StraightTextElement ste(params); @@ -428,8 +426,7 @@ void InformationDisplay::drawEmptyModelMessage(DrawerYG * pDrawer) params.m_log2vis = false; params.m_pivot = pt; params.m_position = yg::EPosCenter; - params.m_rm = pDrawer->screen()->resourceManager().get(); - params.m_skin = pDrawer->screen()->skin().get(); + params.m_glyphCache = pDrawer->screen()->glyphCache(); params.m_logText = strings::FromUtf8(s0); params.m_utf8Text = s0; diff --git a/map/render_queue_routine.cpp b/map/render_queue_routine.cpp index e7d8e02a46..859bc560db 100644 --- a/map/render_queue_routine.cpp +++ b/map/render_queue_routine.cpp @@ -239,6 +239,7 @@ void RenderQueueRoutine::Do() params.m_renderState = m_renderState; params.m_doPeriodicalUpdate = m_doPeriodicalUpdate; params.m_updateInterval = m_updateInterval; + params.m_glyphCacheID = 1; /* params.m_isDebugging = true; params.m_drawPathes = false; params.m_drawAreas = false; diff --git a/yg/font_desc.cpp b/yg/font_desc.cpp index f84f18a732..3f577b8490 100644 --- a/yg/font_desc.cpp +++ b/yg/font_desc.cpp @@ -10,9 +10,9 @@ namespace yg { FontDesc const & FontDesc::defaultFont = FontDesc(); - FontDesc::FontDesc(bool isStatic, int size, yg::Color const & color, + FontDesc::FontDesc(int size, yg::Color const & color, bool isMasked, yg::Color const & maskColor) - : m_isStatic(isStatic), m_size(size), m_color(color), + : m_size(size), m_color(color), m_isMasked(isMasked), m_maskColor(maskColor) {} @@ -24,8 +24,7 @@ namespace yg bool FontDesc::operator ==(FontDesc const & src) const { - return (m_isStatic == src.m_isStatic) - && (m_size == src.m_size) + return (m_size == src.m_size) && (m_color == src.m_color) && (m_isMasked == src.m_isMasked) && (m_maskColor == src.m_maskColor); @@ -38,8 +37,6 @@ namespace yg bool FontDesc::operator < (FontDesc const & src) const { - if (m_isStatic != src.m_isStatic) - return m_isStatic < src.m_isStatic; if (m_size != src.m_size) return m_size < src.m_size; if (m_color != src.m_color) @@ -53,8 +50,6 @@ namespace yg bool FontDesc::operator > (FontDesc const & src) const { - if (m_isStatic != src.m_isStatic) - return m_isStatic > src.m_isStatic; if (m_size != src.m_size) return m_size > src.m_size; if (m_color != src.m_color) diff --git a/yg/font_desc.hpp b/yg/font_desc.hpp index 806dbf4322..b8e108927b 100644 --- a/yg/font_desc.hpp +++ b/yg/font_desc.hpp @@ -6,13 +6,12 @@ namespace yg { struct FontDesc { - bool m_isStatic; int m_size; yg::Color m_color; bool m_isMasked; yg::Color m_maskColor; - FontDesc(bool isStatic = true, int size = 10, yg::Color const & color = yg::Color(0, 0, 0, 255), + FontDesc(int size = 10, yg::Color const & color = yg::Color(0, 0, 0, 255), bool isMasked = true, yg::Color const & maskColor = yg::Color(255, 255, 255, 255)); void SetRank(double rank); diff --git a/yg/glyph_cache.cpp b/yg/glyph_cache.cpp index 43536ea736..e3df728414 100644 --- a/yg/glyph_cache.cpp +++ b/yg/glyph_cache.cpp @@ -45,6 +45,9 @@ namespace yg : m_blocksFile(blocksFile), m_whiteListFile(whiteListFile), m_blackListFile(blackListFile), m_maxSize(maxSize) {} + GlyphCache::GlyphCache() + {} + GlyphCache::GlyphCache(Params const & params) : m_impl(new GlyphCacheImpl(params)) { } @@ -153,7 +156,7 @@ namespace yg return m; } - shared_ptr const GlyphCache::getGlyph(GlyphKey const & key) + shared_ptr const GlyphCache::getGlyphInfo(GlyphKey const & key) { pair charIDX = getCharIDX(key); diff --git a/yg/glyph_cache.hpp b/yg/glyph_cache.hpp index f0324e81fe..f95274b2f2 100644 --- a/yg/glyph_cache.hpp +++ b/yg/glyph_cache.hpp @@ -67,6 +67,7 @@ namespace yg Params(char const * blocksFile, char const * whiteListFile, char const * blackListFile, size_t maxSize); }; + GlyphCache(); GlyphCache(Params const & params); void reset(); @@ -75,7 +76,7 @@ namespace yg pair getCharIDX(GlyphKey const & key); - shared_ptr const getGlyph(GlyphKey const & key); + shared_ptr const getGlyphInfo(GlyphKey const & key); /// return control box(could be slightly larger than the precise bound box). GlyphMetrics const getGlyphMetrics(GlyphKey const & key); diff --git a/yg/glyph_layout.cpp b/yg/glyph_layout.cpp index 5448cbefec..47edb553b9 100644 --- a/yg/glyph_layout.cpp +++ b/yg/glyph_layout.cpp @@ -1,6 +1,4 @@ #include "glyph_layout.hpp" -#include "resource_manager.hpp" -#include "skin.hpp" #include "font_desc.hpp" #include "resource_style.hpp" #include "text_path.hpp" @@ -58,8 +56,7 @@ namespace yg return res; } - GlyphLayout::GlyphLayout(ResourceManager * resourceManager, - Skin * skin, + GlyphLayout::GlyphLayout(GlyphCache * glyphCache, FontDesc const & fontDesc, m2::PointD const & pt, strings::UniString const & visText, @@ -77,67 +74,29 @@ namespace yg { GlyphKey glyphKey(visText[i], fontDesc.m_size, fontDesc.m_isMasked, fontDesc.m_color); - if (fontDesc.m_isStatic) + GlyphMetrics const m = glyphCache->getGlyphMetrics(glyphKey); + if (isFirst) { - uint32_t glyphID = skin->mapGlyph(glyphKey, fontDesc.m_isStatic); - CharStyle const * p = static_cast(skin->fromID(glyphID)); - if (p != 0) - { - if (isFirst) - { - limitRect = m2::RectD(p->m_xOffset + pv.x, - -p->m_yOffset + pv.y, - p->m_xOffset + pv.x, - -p->m_yOffset + pv.y); - isFirst = false; - } - else - limitRect.Add(m2::PointD(p->m_xOffset, -p->m_yOffset) + pv); - - limitRect.Add(m2::PointD(p->m_xOffset + p->m_texRect.SizeX() - 4, - -(p->m_yOffset + (int)p->m_texRect.SizeY() - 4)) + pv); - - } - - GlyphLayoutElem elem; - - elem.m_sym = visText[i]; - elem.m_angle = 0; - elem.m_pt = pv; - elem.m_metrics.m_height = p ? p->m_texRect.SizeY() - 4 : 0; - elem.m_metrics.m_width = p ? p->m_texRect.SizeX() - 4 : 0; - elem.m_metrics.m_xAdvance = p ? p->m_xAdvance : 0; - elem.m_metrics.m_xOffset = p ? p->m_xOffset : 0; - elem.m_metrics.m_yOffset = p ? p->m_yOffset : 0; - elem.m_metrics.m_yAdvance = 0; - - m_entries.push_back(elem); - - pv += m2::PointD(p ? p->m_xAdvance : 0, 0); + limitRect = m2::RectD(m.m_xOffset + pv.x, + -m.m_yOffset + pv.y, + m.m_xOffset + pv.x, + -m.m_yOffset + pv.y); + isFirst = false; } else - { - GlyphMetrics const m = resourceManager->getGlyphMetrics(glyphKey); - if (i == 0) - limitRect = m2::RectD(m.m_xOffset + pv.x, - -m.m_yOffset + pv.y, - m.m_xOffset + pv.x, - -m.m_yOffset + pv.y); - else - limitRect.Add(m2::PointD(m.m_xOffset, -m.m_yOffset) + pv); + limitRect.Add(m2::PointD(m.m_xOffset + pv.x, -m.m_yOffset + pv.y)); - limitRect.Add(m2::PointD(m.m_xOffset + m.m_width, - -(m.m_yOffset + m.m_height)) + pv); + limitRect.Add(m2::PointD(m.m_xOffset + m.m_width, + -(m.m_yOffset + m.m_height)) + pv); - GlyphLayoutElem elem; - elem.m_sym = visText[i]; - elem.m_angle = 0; - elem.m_pt = pv; - elem.m_metrics = m; - m_entries.push_back(elem); + GlyphLayoutElem elem; + elem.m_sym = visText[i]; + elem.m_angle = 0; + elem.m_pt = pv; + elem.m_metrics = m; + m_entries.push_back(elem); - pv += m2::PointD(m.m_xAdvance, m.m_yAdvance); - } + pv += m2::PointD(m.m_xAdvance, m.m_yAdvance); } limitRect.Inflate(2, 2); @@ -165,7 +124,7 @@ namespace yg } - GlyphLayout::GlyphLayout(ResourceManager * resourceManager, + GlyphLayout::GlyphLayout(GlyphCache * glyphCache, FontDesc const & fontDesc, m2::PointD const * pts, size_t ptsCount, @@ -188,7 +147,7 @@ namespace yg for (size_t i = 0; i < m_entries.size(); ++i) { m_entries[i].m_sym = visText[i]; - m_entries[i].m_metrics = resourceManager->getGlyphMetrics(GlyphKey(m_entries[i].m_sym, fontDesc.m_size, fontDesc.m_isMasked, yg::Color(0, 0, 0, 0))); + m_entries[i].m_metrics = glyphCache->getGlyphMetrics(GlyphKey(m_entries[i].m_sym, fontDesc.m_size, fontDesc.m_isMasked, yg::Color(0, 0, 0, 0))); strLength += m_entries[i].m_metrics.m_xAdvance; } diff --git a/yg/glyph_layout.hpp b/yg/glyph_layout.hpp index 6758bd5eb6..04649c2f0d 100644 --- a/yg/glyph_layout.hpp +++ b/yg/glyph_layout.hpp @@ -17,8 +17,7 @@ namespace yg { - class ResourceManager; - class Skin; + class GlyphCache; struct FontDesc; struct GlyphLayoutElem @@ -47,14 +46,13 @@ namespace yg GlyphLayout(GlyphLayout const & layout, double shift); - GlyphLayout(ResourceManager * resourceManager, - Skin * skin, + GlyphLayout(GlyphCache * glyphCache, FontDesc const & font, m2::PointD const & pt, strings::UniString const & visText, yg::EPosition pos); - GlyphLayout(ResourceManager * resourceManager, + GlyphLayout(GlyphCache * glyphCache, FontDesc const & font, m2::PointD const * pts, size_t ptsCount, diff --git a/yg/resource_manager.cpp b/yg/resource_manager.cpp index 29f2d93f3e..b08947015f 100644 --- a/yg/resource_manager.cpp +++ b/yg/resource_manager.cpp @@ -31,11 +31,16 @@ namespace yg m_vbSize(vbSize), m_ibSize(ibSize), m_smallVBSize(smallVBSize), m_smallIBSize(smallIBSize), m_blitVBSize(blitVBSize), m_blitIBSize(blitIBSize), - m_glyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize)), m_format(fmt), m_useVA(useVA), m_fillSkinAlpha(fillSkinAlpha) { + + /// primary cache is for rendering, so it's big + m_glyphCaches.push_back(GlyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, maxGlyphCacheSize))); + /// secondary caches is for glyph metrics only, so they are small + m_glyphCaches.push_back(GlyphCache(GlyphCache::Params(blocksFile, whiteListFile, blackListFile, 500 * 1024))); + if (useVA) { LOG(LINFO, ("buffer objects are unsupported. using client vertex array instead.")); @@ -197,24 +202,15 @@ namespace yg } } - shared_ptr const ResourceManager::getGlyphInfo(GlyphKey const & key) + GlyphCache * ResourceManager::glyphCache(int glyphCacheID) { - return m_glyphCache.getGlyph(key); - } - - GlyphMetrics const ResourceManager::getGlyphMetrics(GlyphKey const & key) - { - return m_glyphCache.getGlyphMetrics(key); - } - - GlyphCache * ResourceManager::getGlyphCache() - { - return &m_glyphCache; + return &m_glyphCaches[glyphCacheID]; } void ResourceManager::addFonts(vector const & fontNames) { - m_glyphCache.addFonts(fontNames); + for (unsigned i = 0; i < m_glyphCaches.size(); ++i) + m_glyphCaches[i].addFonts(fontNames); } void ResourceManager::memoryWarning() diff --git a/yg/resource_manager.hpp b/yg/resource_manager.hpp index ae3287ff1c..cf68d74d7d 100644 --- a/yg/resource_manager.hpp +++ b/yg/resource_manager.hpp @@ -59,7 +59,7 @@ namespace yg gl::Storage const reserveStorageImpl(bool doWait, list & l); void freeStorageImpl(gl::Storage const & storage, bool doSignal, list & l); - GlyphCache m_glyphCache; + vector m_glyphCaches; RtFormat m_format; @@ -96,7 +96,7 @@ namespace yg shared_ptr const getGlyphInfo(GlyphKey const & key); GlyphMetrics const getGlyphMetrics(GlyphKey const & key); - GlyphCache * getGlyphCache(); + GlyphCache * glyphCache(int glyphCacheID = 0); void addFonts(vector const & fontNames); diff --git a/yg/skin.cpp b/yg/skin.cpp index 7f32aa0afb..03e16f540a 100644 --- a/yg/skin.cpp +++ b/yg/skin.cpp @@ -180,24 +180,21 @@ namespace yg return true; } - uint32_t Skin::mapGlyph(GlyphKey const & gk, bool isFixedFont) + uint32_t Skin::mapGlyph(GlyphKey const & gk, GlyphCache * glyphCache) { uint32_t res = invalidPageHandle(); for (uint8_t i = 0; i < m_pages.size(); ++i) { - res = m_pages[i]->findGlyph(gk, isFixedFont); + res = m_pages[i]->findGlyph(gk); if (res != invalidPageHandle()) return packID(i, res); } - if (isFixedFont) - return res; - - if (!m_pages[m_currentTextPage]->hasRoom(gk)) + if (!m_pages[m_currentTextPage]->hasRoom(gk, glyphCache)) changeCurrentTextPage(); - return packID(m_currentTextPage, m_pages[m_currentTextPage]->mapGlyph(gk)); + return packID(m_currentTextPage, m_pages[m_currentTextPage]->mapGlyph(gk, glyphCache)); } Skin::TSkinPages const & Skin::pages() const diff --git a/yg/skin.hpp b/yg/skin.hpp index 01d6bee75e..415ab8e1e8 100644 --- a/yg/skin.hpp +++ b/yg/skin.hpp @@ -32,6 +32,7 @@ namespace yg struct CircleInfo; struct Color; struct GlyphKey; + class GlyphCache; struct FontInfo; class Skin @@ -126,7 +127,7 @@ namespace yg /// find glyph identified by GlyphKey on texture /// if found - return id /// if not - pack and return id - uint32_t mapGlyph(GlyphKey const & gk, bool isFixedFont); + uint32_t mapGlyph(GlyphKey const & gk, GlyphCache * glyphCache); /// find circleStyle on texture /// if found - return id /// if not - pack and return id diff --git a/yg/skin_page.cpp b/yg/skin_page.cpp index c9e2930d11..802329f314 100644 --- a/yg/skin_page.cpp +++ b/yg/skin_page.cpp @@ -203,40 +203,8 @@ namespace yg return it->second; } - uint32_t SkinPage::findGlyph(GlyphKey const & g, bool isFixedFont) const + uint32_t SkinPage::findGlyph(GlyphKey const & g) const { - if (isFixedFont) - { - TStyles::const_iterator styleIt = m_styles.find(g.toUInt32()); - if (styleIt != m_styles.end()) - return g.toUInt32(); - TFonts::const_iterator fontIt = m_fonts.begin(); - int lastFontSize = 0; - if (!m_fonts.empty()) - lastFontSize = m_fonts[0].m_fontSize; - - for (TFonts::const_iterator it = m_fonts.begin(); it != m_fonts.end(); ++it) - if ((lastFontSize < g.m_fontSize) && (g.m_fontSize >= it->m_fontSize)) - fontIt = it; - else - lastFontSize = it->m_fontSize; - - if (fontIt != m_fonts.end()) - { - FontInfo::TChars::const_iterator charIt = fontIt->m_chars.find(g.m_symbolCode); - if (charIt != fontIt->m_chars.end()) - { - if (g.m_isMask) - const_cast(m_styles)[g.toUInt32()] = charIt->second.second; - else - const_cast(m_styles)[g.toUInt32()]= charIt->second.first; - return g.toUInt32(); - } - } - - return m_packer.invalidHandle(); - } - TGlyphMap::const_iterator it = m_glyphMap.find(g); if (it == m_glyphMap.end()) return m_packer.invalidHandle(); @@ -244,13 +212,13 @@ namespace yg return it->second; } - uint32_t SkinPage::mapGlyph(yg::GlyphKey const & g) + uint32_t SkinPage::mapGlyph(yg::GlyphKey const & g, yg::GlyphCache * glyphCache) { - uint32_t foundHandle = findGlyph(g, false); + uint32_t foundHandle = findGlyph(g); if (foundHandle != m_packer.invalidHandle()) return foundHandle; - shared_ptr gi = m_resourceManager->getGlyphInfo(g); + shared_ptr gi = glyphCache->getGlyphInfo(g); m2::Packer::handle_t handle = m_packer.pack(gi->m_metrics.m_width + 4, gi->m_metrics.m_height + 4); @@ -269,9 +237,9 @@ namespace yg return m_glyphMap[g]; } - bool SkinPage::hasRoom(GlyphKey const & gk) const + bool SkinPage::hasRoom(GlyphKey const & gk, GlyphCache * glyphCache) const { - shared_ptr gi = m_resourceManager->getGlyphInfo(gk); + shared_ptr gi = glyphCache->getGlyphInfo(gk); return m_packer.hasRoom(gi->m_metrics.m_width + 4, gi->m_metrics.m_height + 4); } diff --git a/yg/skin_page.hpp b/yg/skin_page.hpp index 00626d0a16..543d967901 100644 --- a/yg/skin_page.hpp +++ b/yg/skin_page.hpp @@ -165,9 +165,9 @@ namespace yg uint32_t mapCircleInfo(CircleInfo const & circleInfo); bool hasRoom(CircleInfo const & circleInfo) const; - uint32_t findGlyph(GlyphKey const & g, bool isFixedFont) const; - uint32_t mapGlyph(GlyphKey const & g); - bool hasRoom(GlyphKey const & g) const; + uint32_t findGlyph(GlyphKey const & g) const; + uint32_t mapGlyph(GlyphKey const & g, GlyphCache * glyphCache); + bool hasRoom(GlyphKey const & g, GlyphCache * glyphCache) const; uint32_t findSymbol(char const * symbolName) const; diff --git a/yg/text_element.cpp b/yg/text_element.cpp index 6c3d0734f6..8d1aab8452 100644 --- a/yg/text_element.cpp +++ b/yg/text_element.cpp @@ -63,8 +63,7 @@ namespace yg m_fontDesc(p.m_fontDesc), m_logText(p.m_logText), m_log2vis(p.m_log2vis), - m_rm(p.m_rm), - m_skin(p.m_skin), + m_glyphCache(p.m_glyphCache), m_utf8Text(p.m_utf8Text) { if (m_log2vis) @@ -103,10 +102,10 @@ namespace yg for (unsigned i = layout.firstVisible(); i < layout.lastVisible(); ++i) { - shared_ptr const & skin = screen->skin(); + 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, fontDesc.m_isStatic); + uint32_t const glyphID = skin->mapGlyph(glyphKey, screen->glyphCache()); CharStyle const * charStyle = static_cast(skin->fromID(glyphID)); screen->drawGlyph(elem.m_pt + offset, m2::PointD(0.0, 0.0), elem.m_angle, 0, charStyle, depth); @@ -115,8 +114,7 @@ namespace yg StraightTextElement::StraightTextElement(Params const & p) : TextElement(p), - m_glyphLayout(p.m_rm, - p.m_skin, + m_glyphLayout(p.m_glyphCache, p.m_fontDesc, p.m_pivot, visText(), @@ -154,7 +152,7 @@ namespace yg PathTextElement::PathTextElement(Params const & p) : TextElement(p), - m_glyphLayout(p.m_rm, + m_glyphLayout(p.m_glyphCache, p.m_fontDesc, p.m_pts, p.m_ptsCount, diff --git a/yg/text_element.hpp b/yg/text_element.hpp index 82c3c61c20..fef63bc38e 100644 --- a/yg/text_element.hpp +++ b/yg/text_element.hpp @@ -67,8 +67,7 @@ namespace yg strings::UniString m_logText; //< logical string strings::UniString m_visText; //< visual string, BIDI processed bool m_log2vis; - ResourceManager * m_rm; - Skin * m_skin; + GlyphCache * m_glyphCache; strings::UniString log2vis(strings::UniString const & str); @@ -79,15 +78,19 @@ namespace yg FontDesc m_fontDesc; wstring m_logText; bool m_log2vis; - ResourceManager * m_rm; - Skin * m_skin; + GlyphCache * m_glyphCache; }; TextElement(Params const & p); - void drawTextImpl(GlyphLayout const & layout, gl::TextRenderer * screen, FontDesc const & desc, double depth) const; - strings::UniString const & logText() const; - strings::UniString const & visText() const; + void drawTextImpl(GlyphLayout const & layout, + gl::TextRenderer * screen, + math::Matrix const & m, + FontDesc const & desc, + double depth) const; + wstring const & logText() const; + wstring const & visText() const; + string const & utf8Text() const; FontDesc const & fontDesc() const; }; diff --git a/yg/text_renderer.cpp b/yg/text_renderer.cpp index 123b46d35a..71500ac042 100644 --- a/yg/text_renderer.cpp +++ b/yg/text_renderer.cpp @@ -17,12 +17,14 @@ namespace yg { TextRenderer::Params::Params() - : m_drawTexts(true) + : m_drawTexts(true), + m_glyphCacheID(0) {} TextRenderer::TextRenderer(Params const & params) : base_t(params), - m_drawTexts(params.m_drawTexts) + m_drawTexts(params.m_drawTexts), + m_glyphCacheID(params.m_glyphCacheID) {} void TextRenderer::drawText(FontDesc const & fontDesc, @@ -42,13 +44,12 @@ namespace yg params.m_log2vis = log2vis; params.m_pivot = pt; params.m_position = pos; - params.m_rm = resourceManager().get(); - params.m_skin = skin().get(); + params.m_glyphCache = resourceManager()->glyphCache(m_glyphCacheID); params.m_logText = strings::MakeUniString(utf8Text); - + StraightTextElement ste(params); - if (!renderState().get() || fontDesc.m_isStatic) + if (!renderState().get()) ste.draw(this, math::Identity()); else renderState()->m_currentInfoLayer->addStraightText(ste); @@ -71,14 +72,13 @@ namespace yg params.m_logText = strings::FromUtf8(utf8Text); params.m_depth = depth; params.m_log2vis = true; - params.m_rm = resourceManager().get(); - params.m_skin = skin().get(); + params.m_glyphCache = resourceManager()->glyphCache(m_glyphCacheID); params.m_pivot = path[0]; params.m_position = pos; PathTextElement pte(params); - if (!renderState().get() || fontDesc.m_isStatic) + if (!renderState().get()) pte.draw(this, math::Identity()); else renderState()->m_currentInfoLayer->addPathText(pte); @@ -102,5 +102,10 @@ namespace yg depth, p->m_pageID); } + + GlyphCache * TextRenderer::glyphCache() const + { + return resourceManager()->glyphCache(m_glyphCacheID); + } } } diff --git a/yg/text_renderer.hpp b/yg/text_renderer.hpp index 0290b9c0f9..a2fd41e278 100644 --- a/yg/text_renderer.hpp +++ b/yg/text_renderer.hpp @@ -37,6 +37,7 @@ namespace yg bool log2vis); bool m_drawTexts; + int m_glyphCacheID; public: @@ -45,6 +46,7 @@ namespace yg struct Params : base_t::Params { bool m_drawTexts; + int m_glyphCacheID; Params(); }; @@ -75,6 +77,8 @@ namespace yg double pathOffset, yg::EPosition pos, double depth); + + GlyphCache * glyphCache() const; }; } } diff --git a/yg/yg_tests/glyph_cache_test.cpp b/yg/yg_tests/glyph_cache_test.cpp index 3d75f684c4..9f17b82343 100644 --- a/yg/yg_tests/glyph_cache_test.cpp +++ b/yg/yg_tests/glyph_cache_test.cpp @@ -14,8 +14,8 @@ UNIT_TEST(GlyphCacheTest_Main) 200000)); cache.addFont((path + "01_dejavusans.ttf").c_str()); - shared_ptr g1 = cache.getGlyph(yg::GlyphKey('#', 40, true, yg::Color(255, 255, 255, 255))); + shared_ptr g1 = cache.getGlyphInfo(yg::GlyphKey('#', 40, true, yg::Color(255, 255, 255, 255))); // g1->dump(GetPlatform().WritablePathForFile("#_mask.png").c_str()); - shared_ptr g2 = cache.getGlyph(yg::GlyphKey('#', 40, false, yg::Color(0, 0, 0, 0))); + shared_ptr g2 = cache.getGlyphInfo(yg::GlyphKey('#', 40, false, yg::Color(0, 0, 0, 0))); // g2->dump(GetPlatform().WritablePathForFile("#.png").c_str()); } diff --git a/yg/yg_tests/screengl_test.cpp b/yg/yg_tests/screengl_test.cpp index 1a058bca5e..517ab53173 100644 --- a/yg/yg_tests/screengl_test.cpp +++ b/yg/yg_tests/screengl_test.cpp @@ -598,7 +598,7 @@ namespace double pat[2] = {2, 2}; p->drawPath(path, sizeof(path) / sizeof(m2::PointD), 0, p->skin()->mapPenInfo(yg::PenInfo(yg::Color(0, 0, 0, 0xFF), 2, pat, 2, 0)), 0); - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(200, 200), yg::EPosAboveRight, 0 , "0", 0, true); p->drawText(fontDesc, m2::PointD(240, 200), yg::EPosAboveRight, math::pi / 2 , "0", 0, true); @@ -613,7 +613,7 @@ namespace { void DoDraw(shared_ptr p) { - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0, "X", 1, true); } }; @@ -622,7 +622,7 @@ namespace { void DoDraw(shared_ptr p) { - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0, " ", 1, true); } }; @@ -634,7 +634,7 @@ namespace size_t const maxTimes = 10; size_t const yStep = 30; - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); for (size_t i = 0; i < maxTimes; ++i) for (size_t j = 1; j <= i+1; ++j) @@ -654,7 +654,7 @@ namespace yg::PenInfo penInfo = yg::PenInfo(yg::Color(0, 0, 0, 0xFF), 2, &pat[0], ARRAY_SIZE(pat), 0); yg::PenInfo solidPenInfo = yg::PenInfo(yg::Color(0xFF, 0, 0, 0xFF), 4, 0, 0, 0); - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0, "S", 0, true); p->drawPath(&path[0], path.size(), 0, p->skin()->mapPenInfo(solidPenInfo), 0); @@ -666,24 +666,16 @@ namespace { void DoDraw(shared_ptr p) { - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0/*, math::pi / 18*/, "Simplicity is the ultimate sophistication", 0, true); } }; - struct TestDrawStringWithFixedFont - { - void DoDraw(shared_ptr p) - { - p->drawText(yg::FontDesc::defaultFont, m2::PointD(40, 50), yg::EPosAboveRight, 0/*, math::pi / 18*/, "Simplicity is the ultimate sophistication", 0, true); - } - }; - struct TestDrawStringWithColor { void DoDraw(shared_ptr p) { - yg::FontDesc fontDesc(false, 25, yg::Color(0, 0, 255, 255), true, yg::Color(255, 255, 255, 255)); + yg::FontDesc fontDesc(25, yg::Color(0, 0, 255, 255), true, yg::Color(255, 255, 255, 255)); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0/*, math::pi / 18*/, "Simplicity is the ultimate sophistication", 0, true); } }; @@ -693,7 +685,7 @@ namespace { void DoDraw(shared_ptr p) { - yg::FontDesc fontDesc(false, 12); + yg::FontDesc fontDesc(12); p->drawText(fontDesc, m2::PointD(40, 50), yg::EPosAboveRight, 0, "Latin Symbol : A", 0, true); p->drawText(fontDesc, m2::PointD(40, 80), yg::EPosAboveRight, 0, "Cyrillic Symbol : Ы", 0, true); } @@ -708,36 +700,11 @@ namespace yg::StraightTextElement::Params params; params.m_depth = 0; - params.m_fontDesc = yg::FontDesc(false, 20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); + params.m_fontDesc = yg::FontDesc(20, yg::Color(0, 0, 0, 0), true, yg::Color(255, 255, 255, 255)); params.m_log2vis = false; params.m_pivot = startPt; params.m_position = yg::EPosAboveRight; - params.m_rm = p->resourceManager().get(); - params.m_skin = p->skin().get(); - params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication"); - yg::StraightTextElement ste(params); - - m2::AARectD r = ste.boundRect(); - p->drawRectangle(r, yg::Color(0, 0, 255, 255), 0); - - base_t::DoDraw(p); - } - }; - - struct TestDrawTextRectWithFixedFont : TestDrawStringWithFixedFont - { - typedef TestDrawStringWithFixedFont base_t; - void DoDraw(shared_ptr p) - { - m2::PointD startPt(40, 50); - yg::StraightTextElement::Params params; - params.m_depth = 0; - params.m_fontDesc = yg::FontDesc::defaultFont; - params.m_log2vis = false; - params.m_pivot = startPt; - params.m_position = yg::EPosAboveRight; - params.m_rm = p->resourceManager().get(); - params.m_skin = p->skin().get(); + params.m_glyphCache = p->glyphCache(); params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication"); yg::StraightTextElement ste(params); @@ -778,7 +745,7 @@ namespace void DoDraw(shared_ptr p) { p->drawPath(&m_path[0], m_path.size(), 0, p->skin()->mapPenInfo(m_penInfo), 1); - yg::FontDesc fontDesc(false, 30); + yg::FontDesc fontDesc(30); p->drawPathText(fontDesc, &m_path[0], m_path.size(), m_text, calc_length(m_path), 0.0, yg::EPosLeft, 0); } @@ -825,7 +792,7 @@ namespace void DoDraw(shared_ptr p) { p->drawPath(&m_testPoints[0], m_testPoints.size(), 0, p->skin()->mapPenInfo(yg::PenInfo(yg::Color(255, 255, 255, 255), 2, 0, 0, 0)), 0); - yg::FontDesc fontDesc(false, 20, yg::Color(0, 0, 0, 255), false); + yg::FontDesc fontDesc(20, yg::Color(0, 0, 0, 255), false); //m_text = "Simplicity is the ultimate sophistication. Leonardo Da Vinci."; m_text = "Vinci"; p->drawPathText(fontDesc, &m_testPoints[0], m_testPoints.size(), m_text.c_str(), calc_length(m_testPoints), m_pathOffset, yg::EPosLeft, 1); @@ -854,7 +821,7 @@ namespace void DoDraw(shared_ptr p) { p->drawPath(&m_path[0], m_path.size(), 0, p->skin()->mapPenInfo(m_penInfo), 0); - yg::FontDesc fontDesc(false, 20); + yg::FontDesc fontDesc(20); p->drawPathText(fontDesc, &m_path[0], m_path.size(), m_text, calc_length(m_path), 0.0, yg::EPosCenter, 0); } }; @@ -874,12 +841,11 @@ namespace void DoDraw(shared_ptr p) { yg::StraightTextElement::Params params; - params.m_fontDesc = yg::FontDesc(false, 20); + params.m_fontDesc = yg::FontDesc(20); params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication. Leonardo Da Vinci."); params.m_depth = 10; params.m_log2vis = false; - params.m_rm = p->resourceManager().get(); - params.m_skin = p->skin().get(); + params.m_glyphCache = p->glyphCache(); params.m_pivot = m_path[0]; params.m_position = yg::EPosRight; @@ -918,12 +884,11 @@ namespace params.m_ptsCount = m_path.size(); params.m_fullLength = calc_length(m_path); params.m_pathOffset = 0; - params.m_fontDesc = yg::FontDesc(false, 20); + params.m_fontDesc = yg::FontDesc(20); params.m_logText = strings::MakeUniString("Simplicity is the ultimate sophistication. Leonardo Da Vinci."); params.m_depth = 10; params.m_log2vis = false; - params.m_rm = p->resourceManager().get(); - params.m_skin = p->skin().get(); + params.m_glyphCache = p->glyphCache(); params.m_pivot = m_path[0]; params.m_position = yg::EPosCenter; @@ -961,7 +926,7 @@ namespace { p->drawPath(&m_path[0], m_path.size(), 0, p->skin()->mapPenInfo(m_penInfo), 0); // yg::FontDesc fontDesc(false, 10); - yg::FontDesc fontDesc(false, 20); + yg::FontDesc fontDesc(20); p->drawPathText(fontDesc, &m_path[0], m_path.size(), m_text, calc_length(m_path), 0.0, yg::EPosCenter, 0); } }; @@ -990,7 +955,7 @@ namespace p->drawPath(&m_pathUnder[0], m_pathUnder.size(), 0, p->skin()->mapPenInfo(m_penInfo), 0); double const len = calc_length(m_path); - yg::FontDesc fontDesc(false, 20); + yg::FontDesc fontDesc(20); p->drawPathText(fontDesc, &m_pathAbove[0], m_pathAbove.size(), m_text, len, 0.0, yg::EPosAbove, 0); p->drawPathText(fontDesc, &m_pathUnder[0], m_pathUnder.size(), m_text, len, 0.0, yg::EPosUnder, 0); @@ -1007,7 +972,7 @@ namespace int startY = 30; for (size_t i = 0; i < sizesCount; ++i) { - yg::FontDesc fontDesc(false, startSize + i); + yg::FontDesc fontDesc(startSize + i); p->drawText(fontDesc, m2::PointD(10, startY), yg::EPosAboveRight, 0, "Simplicity is the ultimate sophistication. Leonardo Da Vinci", 0, true); startY += fontDesc.m_size; } @@ -1024,7 +989,7 @@ namespace int startY = 30; for (size_t i = 0; i < sizesCount; ++i) { - yg::FontDesc fontDesc(false, startSize); + yg::FontDesc fontDesc(startSize); p->drawText(fontDesc, m2::PointD(10, startY), yg::EPosAboveRight, 0, "Simplicity is the ultimate sophistication. Leonardo Da Vinci", 100, true); p->drawText(fontDesc, m2::PointD(5, startY + (startSize + i) / 2), yg::EPosAboveRight, 0, "This text should be filtered", 100, true); startY += startSize + i; @@ -1045,8 +1010,7 @@ namespace for (int i = 0; i < textsCount; ++i) { - yg::FontDesc fontDesc(false, - rand() % (endSize - startSize) + startSize, + yg::FontDesc fontDesc(rand() % (endSize - startSize) + startSize, yg::Color(rand() % 255, rand() % 255, rand() % 255, 255) ); p->drawText(