diff --git a/src/Text/AbstractFont.cpp b/src/Text/AbstractFont.cpp index 52c9feaff..aa8e054e1 100644 --- a/src/Text/AbstractFont.cpp +++ b/src/Text/AbstractFont.cpp @@ -124,7 +124,12 @@ void AbstractFont::fillGlyphCache(GlyphCache& cache, const std::string& characte doFillGlyphCache(cache, Utility::Unicode::utf32(characters)); } -void AbstractFont::doFillGlyphCache(GlyphCache&, const std::u32string&) { +#ifndef _WIN32 +void AbstractFont::doFillGlyphCache(GlyphCache&, const std::u32string&) +#else +void AbstractFont::doFillGlyphCache(GlyphCache&, const std::vector&) +#endif +{ CORRADE_ASSERT(false, "Text::AbstractFont::fillGlyphCache(): feature advertised but not implemented", ); } diff --git a/src/Text/AbstractFont.h b/src/Text/AbstractFont.h index bab9763cd..6f20f9197 100644 --- a/src/Text/AbstractFont.h +++ b/src/Text/AbstractFont.h @@ -250,8 +250,15 @@ class MAGNUM_TEXT_EXPORT AbstractFont: public PluginManager::AbstractPlugin { * * The string is converted from UTF-8 to UTF-32, unique characters are * *not* removed. + * @note On Windows uses `std::vector` instead of + * `std::u32string`. See @ref Corrade::Utility::Unicode::utf32() + * for more information. */ + #ifndef _WIN32 virtual void doFillGlyphCache(GlyphCache& cache, const std::u32string& characters); + #else + virtual void doFillGlyphCache(GlyphCache& cache, const std::vector& characters); + #endif /** * @brief Implementation for createGlyphCache() diff --git a/src/Text/AbstractFontConverter.cpp b/src/Text/AbstractFontConverter.cpp index 8487a0f61..845ad48c1 100644 --- a/src/Text/AbstractFontConverter.cpp +++ b/src/Text/AbstractFontConverter.cpp @@ -43,7 +43,12 @@ std::vector>> AbstractFo return doExportFontToData(font, cache, filename, uniqueUnicode(characters)); } -std::vector>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const { +#ifndef _WIN32 +std::vector>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const +#else +std::vector>> AbstractFontConverter::doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const +#endif +{ CORRADE_ASSERT(!(features() & Feature::MultiFile), "Text::AbstractFontConverter::exportFontToData(): feature advertised but not implemented", {}); @@ -61,7 +66,12 @@ Containers::Array AbstractFontConverter::exportFontToSingleData(A return doExportFontToSingleData(font, cache, uniqueUnicode(characters)); } -Containers::Array AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const { +#ifndef _WIN32 +Containers::Array AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const +#else +Containers::Array AbstractFontConverter::doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector&) const +#endif +{ CORRADE_ASSERT(false, "Text::AbstractFontConverter::exportFontToSingleData(): feature advertised but not implemented", nullptr); } @@ -73,7 +83,12 @@ bool AbstractFontConverter::exportFontToFile(AbstractFont& font, GlyphCache& cac return doExportFontToFile(font, cache, filename, uniqueUnicode(characters)); } -bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const { +#ifndef _WIN32 +bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const +#else +bool AbstractFontConverter::doExportFontToFile(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const +#endif +{ CORRADE_ASSERT(features() & Feature::ConvertData, "Text::AbstractFontConverter::exportFontToFile(): not implemented", false); @@ -214,9 +229,18 @@ GlyphCache* AbstractFontConverter::doImportGlyphCacheFromFile(const std::string& return doImportGlyphCacheFromSingleData(data); } -std::u32string AbstractFontConverter::uniqueUnicode(const std::string& characters) { +#ifndef _WIN32 +std::u32string AbstractFontConverter::uniqueUnicode(const std::string& characters) +#else +std::vector AbstractFontConverter::uniqueUnicode(const std::string& characters) +#endif +{ /* Convert UTF-8 to UTF-32 */ + #ifndef _WIN32 std::u32string result = Utility::Unicode::utf32(characters); + #else + std::vector result = Utility::Unicode::utf32(characters); + #endif /* Remove duplicate glyphs */ std::sort(result.begin(), result.end()); diff --git a/src/Text/AbstractFontConverter.h b/src/Text/AbstractFontConverter.h index 2ea3c0aad..f674fb17f 100644 --- a/src/Text/AbstractFontConverter.h +++ b/src/Text/AbstractFontConverter.h @@ -250,11 +250,28 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl * * If the plugin doesn't have @ref Feature "Feature::MultiFile", * default implementation calls doExportFontToSingleData(). + * @note On Windows uses `std::vector` instead of + * `std::u32string`. See @ref Corrade::Utility::Unicode::utf32() + * for more information. */ + #ifndef _WIN32 virtual std::vector>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const; + #else + virtual std::vector>> doExportFontToData(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const; + #endif - /** @brief Implementation for exportFontToSingleData() */ + /** + * @brief Implementation for exportFontToSingleData() + * + * @note On Windows uses `std::vector` instead of + * `std::u32string`. See @ref Corrade::Utility::Unicode::utf32() + * for more information. + */ + #ifndef _WIN32 virtual Containers::Array doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::u32string& characters) const; + #else + virtual Containers::Array doExportFontToSingleData(AbstractFont& font, GlyphCache& cache, const std::vector& characters) const; + #endif /** * @brief Implementation for exportFontToFile() @@ -262,8 +279,15 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl * If @ref Feature "Feature::ConvertData" is supported, default * implementation calls doExportFontToData() and saves the result to * given file(s). + * @note On Windows uses `std::vector` instead of + * `std::u32string`. See @ref Corrade::Utility::Unicode::utf32() + * for more information. */ + #ifndef _WIN32 virtual bool doExportFontToFile(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::u32string& characters) const; + #else + virtual bool doExportFontToFile(AbstractFont& font, GlyphCache& cache, const std::string& filename, const std::vector& characters) const; + #endif /** * @brief Implementation for exportGlyphCacheToData() @@ -307,7 +331,11 @@ class MAGNUM_TEXT_EXPORT AbstractFontConverter: public PluginManager::AbstractPl virtual GlyphCache* doImportGlyphCacheFromFile(const std::string& filename) const; private: + #ifndef _WIN32 MAGNUM_TEXT_LOCAL static std::u32string uniqueUnicode(const std::string& characters); + #else + MAGNUM_TEXT_LOCAL static std::vector uniqueUnicode(const std::string& characters); + #endif }; CORRADE_ENUMSET_OPERATORS(AbstractFontConverter::Features) diff --git a/src/Text/Test/AbstractFontConverterTest.cpp b/src/Text/Test/AbstractFontConverterTest.cpp index 643f45242..ee970473e 100644 --- a/src/Text/Test/AbstractFontConverterTest.cpp +++ b/src/Text/Test/AbstractFontConverterTest.cpp @@ -65,24 +65,45 @@ AbstractFontConverterTest::AbstractFontConverterTest() { void AbstractFontConverterTest::convertGlyphs() { class GlyphExporter: public AbstractFontConverter { public: + #ifndef _WIN32 GlyphExporter(std::u32string& characters): characters(characters) {} + #else + GlyphExporter(std::vector& characters): characters(characters) {} + #endif private: Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; } - Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string& characters) const override { + #ifndef _WIN32 + Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string& characters) const override + #else + Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector& characters) const override + #endif + { this->characters = characters; return nullptr; } + #ifndef _WIN32 std::u32string& characters; + #else + std::vector& characters; + #endif }; + #ifndef _WIN32 std::u32string characters; + #else + std::vector characters; + #endif GlyphExporter exporter(characters); exporter.exportFontToSingleData(*static_cast(nullptr), *static_cast(nullptr), "abC01a0 "); - CORRADE_COMPARE(characters, (std::u32string{ + #ifndef _WIN32 + CORRADE_COMPARE(characters, U" 01Cab"); + #else + CORRADE_COMPARE(characters, (std::vector{ U' ', U'0', U'1', U'C', U'a', U'b'})); + #endif } void AbstractFontConverterTest::exportFontToSingleData() { @@ -90,7 +111,12 @@ void AbstractFontConverterTest::exportFontToSingleData() { private: Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont; } - Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const override { + #ifndef _WIN32 + Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::u32string&) const override + #else + Containers::Array doExportFontToSingleData(AbstractFont&, GlyphCache&, const std::vector&) const override + #endif + { Containers::Array data(1); data[0] = 0xee; return std::move(data); @@ -111,7 +137,12 @@ void AbstractFontConverterTest::exportFontToFile() { private: Features doFeatures() const override { return Feature::ConvertData|Feature::ExportFont|Feature::MultiFile; } - std::vector>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::u32string&) const override { + #ifndef _WIN32 + std::vector>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::u32string&) const override + #else + std::vector>> doExportFontToData(AbstractFont&, GlyphCache&, const std::string& filename, const std::vector&) const override + #endif + { Containers::Array file(1); file[0] = 0xf0;