diff --git a/base/base.pro b/base/base.pro index 4ebc56f18a..355dc248cd 100644 --- a/base/base.pro +++ b/base/base.pro @@ -18,7 +18,6 @@ SOURCES += \ commands_queue.cpp \ shared_buffer_manager.cpp \ memory_mapped_file.cpp \ - path_utils.cpp \ condition.cpp \ lower_case.cpp \ normalize_unicode.cpp \ @@ -65,7 +64,6 @@ HEADERS += \ shared_buffer_manager.hpp \ memory_mapped_file.hpp \ buffer_vector.hpp \ - path_utils.hpp \ array_adapters.hpp \ runner.hpp \ object_pool.hpp diff --git a/base/path_utils.cpp b/base/path_utils.cpp deleted file mode 100644 index a18a79b954..0000000000 --- a/base/path_utils.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "../base/SRC_FIRST.hpp" - -#include "path_utils.hpp" -#include "string_utils.hpp" - - -string const extract_name(string const & fileName) -{ - return fileName.substr(fileName.find_last_of("\\/") + 1, fileName.size()); -} diff --git a/base/path_utils.hpp b/base/path_utils.hpp deleted file mode 100644 index be1a37e174..0000000000 --- a/base/path_utils.hpp +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "../std/string.hpp" - -/// extract file name from full path. -string const extract_name(string const & fileName); diff --git a/platform/platform.cpp b/platform/platform.cpp index d19a7415b1..0bbf5bc1d7 100644 --- a/platform/platform.cpp +++ b/platform/platform.cpp @@ -90,9 +90,6 @@ void BasePlatformImpl::GetFontNames(FilesList & res) const GetFilesInDir(m_resourcesDir, "*.ttf", res); sort(res.begin(), res.end()); - - for (size_t i = 0; i < res.size(); ++i) - res[i] = m_resourcesDir + res[i]; } double BasePlatformImpl::VisualScale() const diff --git a/yg/glyph_cache_impl.cpp b/yg/glyph_cache_impl.cpp index 09a8d450f4..2d072fce0b 100644 --- a/yg/glyph_cache_impl.cpp +++ b/yg/glyph_cache_impl.cpp @@ -4,7 +4,6 @@ #include "../coding/reader.hpp" -#include "../base/path_utils.hpp" #include "../base/assert.hpp" #include "../std/bind.hpp" @@ -22,13 +21,55 @@ namespace yg return (m_start <= sym) && (m_end >= sym); } - Font::Font(char const * name) : m_name(name), m_fontData(name, true) + /// Called by FreeType to read data + static unsigned long FTStreamIOFunc(FT_Stream stream, + unsigned long offset, + unsigned char * buffer, + unsigned long count) + { + // FreeType can call us with 0 to "Skip" bytes + if (count != 0) + reinterpret_cast *>(stream->descriptor.pointer)->Read(offset, buffer, count); + return count; + } + + static void FTStreamCloseFunc(FT_Stream) { } - FT_Error Font::CreateFaceID(FT_Library library, FT_Face *face) + Font::Font(ReaderPtr const & fontReader) : m_fontReader(fontReader) { - return FT_New_Memory_Face(library, (unsigned char*)m_fontData.data(), m_fontData.size(), 0, face); + m_fontStream = new FT_StreamRec; + m_fontStream->base = 0; + m_fontStream->size = m_fontReader.Size(); + m_fontStream->pos = 0; + m_fontStream->descriptor.pointer = &m_fontReader; + m_fontStream->pathname.pointer = 0; + m_fontStream->read = &FTStreamIOFunc; + m_fontStream->close = &FTStreamCloseFunc; + m_fontStream->memory = 0; + m_fontStream->cursor = 0; + m_fontStream->limit = 0; + } + + Font::~Font() + { + delete m_fontStream; + } + + FT_Error Font::CreateFaceID(FT_Library library, FT_Face * face) + { + FT_Open_Args args; + args.flags = FT_OPEN_STREAM; + args.memory_base = 0; + args.memory_size = 0; + args.pathname = 0; + args.stream = m_fontStream; + args.driver = 0; + args.num_params = 0; + args.params = 0; + return FT_Open_Face(library, &args, 0, face); + //return FT_New_Memory_Face(library, (unsigned char*)m_fontData.data(), m_fontData.size(), 0, face); } void GlyphCacheImpl::initBlocks(string const & fileName) @@ -181,12 +222,8 @@ namespace yg void GlyphCacheImpl::addFont(char const * fileName) { - string fontName = extract_name(fileName); - for (size_t i = 0; i < fontName.size(); ++i) - if (fontName[i] == ' ') - fontName[i] = '_'; - - m_fonts.push_back(make_shared_ptr(new Font(fileName))); + ReaderPtr reader = GetPlatform().GetReader(fileName); + m_fonts.push_back(make_shared_ptr(new Font(reader))); /// obtaining all glyphs, supported by this font FT_Face face; @@ -242,16 +279,16 @@ namespace yg /// checking blacklist and whitelist for (size_t i = 0; i < ubIt->m_blacklist.size(); ++i) - if (ubIt->m_blacklist[i] == fontName) + if (ubIt->m_blacklist[i] == fileName) /// if font is blacklisted for this unicode block ubIt->m_coverage.back() = -1; for (size_t i = 0; i < ubIt->m_whitelist.size(); ++i) - if (ubIt->m_whitelist[i] == fontName) + if (ubIt->m_whitelist[i] == fileName) { if (ubIt->m_coverage.back() == -1) { - LOG(LWARNING, ("font ", fontName, "is present both at blacklist and whitelist. whitelist prevails.")); + LOG(LWARNING, ("font ", fileName, "is present both at blacklist and whitelist. whitelist prevails.")); } /// weight used for sorting are boosted to the top. /// the order of elements are saved by adding 'i' value as a shift. diff --git a/yg/glyph_cache_impl.hpp b/yg/glyph_cache_impl.hpp index bfc14206c7..e283b1e873 100644 --- a/yg/glyph_cache_impl.hpp +++ b/yg/glyph_cache_impl.hpp @@ -3,26 +3,28 @@ #include "glyph_cache.hpp" #include "ft2_debug.hpp" -#include "../base/memory_mapped_file.hpp" #include "../base/string_utils.hpp" +#include "../coding/reader.hpp" + #include "../std/string.hpp" #include "../std/vector.hpp" #include "../std/shared_ptr.hpp" +#include namespace yg { struct Font { - string m_name; - - MemoryMappedFile m_fontData; + FT_Stream m_fontStream; + ReaderPtr m_fontReader; /// information about symbol ranges /// ... /// constructor - Font(char const * name); + Font(ReaderPtr const & fontReader); + ~Font(); FT_Error CreateFaceID(FT_Library library, FT_Face * face); };