]> git.sesse.net Git - casparcg/commitdiff
* new way of mapping font-name to font-file. Using postscript font-name instead of...
authorniklaspandersson <niklas.p.andersson@svt.se>
Mon, 19 Aug 2013 08:17:30 +0000 (10:17 +0200)
committerniklaspandersson <niklas.p.andersson@svt.se>
Mon, 19 Aug 2013 08:17:30 +0000 (10:17 +0200)
* extracting unicode layer-name from psd-files.

common/env.cpp
common/env.h
common/os/windows/system_info.h
core/producer/text/text_producer.cpp
core/producer/text/utils/texture_font.cpp
modules/psd/layer.cpp
shell/server.cpp

index 817553c7ce829aa7cd14c4a89e22056ff661d485..5aca238f94d4fdf267e2bf8f70f3d60cd231433f 100644 (file)
@@ -43,6 +43,7 @@ std::wstring media;
 std::wstring log;
 std::wstring ftemplate;
 std::wstring data;
+std::wstring font;
 boost::property_tree::wptree pt;
 
 void check_is_configured()
@@ -65,6 +66,7 @@ void configure(const std::wstring& filename)
                log                     = paths.get(L"log-path", initialPath + L"\\log\\");
                ftemplate       = boost::filesystem3::complete(paths.get(L"template-path", initialPath + L"\\template\\")).wstring();           
                data            = paths.get(L"data-path", initialPath + L"\\data\\");
+               font            = paths.get(L"font-path", initialPath + L"\\fonts\\");
 
                try
                {
@@ -150,6 +152,12 @@ const std::wstring& data_folder()
        return data;
 }
 
+const std::wstring& font_folder()
+{
+       check_is_configured();
+       return font;
+}
+
 #define QUOTE(str) #str
 #define EXPAND_AND_QUOTE(str) QUOTE(str)
 
@@ -170,4 +178,9 @@ const boost::property_tree::wptree& properties()
        return pt;
 }
 
+std::wstring system_font_folder()
+{
+       return L"C:\\windows\\Fonts\\";
+}
+
 }}
\ No newline at end of file
index 850cc29dd2446f351d6423ddc333adf08a2a01a4..f68de259f31fe2f8b657726a9802080e1f5b2863 100644 (file)
@@ -35,6 +35,9 @@ const std::wstring& template_folder();
 const std::wstring& data_folder();
 const std::wstring& version();
 
+const std::wstring& font_folder();
+std::wstring system_font_folder();
+
 const boost::property_tree::wptree& properties();
 
 } }
\ No newline at end of file
index 4079fffc96b23a976fa9d6f4f1f43f938f307bd2..ee8d2de9cbdedd5726ad7575241deea026e74983 100644 (file)
@@ -79,7 +79,7 @@ static std::wstring system_product_name()
        return system_product_name;
 }
 
-static std::map<std::wstring, std::wstring> enumerate_fonts()
+/*static std::map<std::wstring, std::wstring> enumerate_fonts()
 {
        std::map<std::wstring, std::wstring> result;
        const DWORD max_str_length = 32766;
@@ -114,6 +114,6 @@ static std::map<std::wstring, std::wstring> enumerate_fonts()
        }
 
        return result;
-}
+}*/
 
 }
\ No newline at end of file
index 6da1507b2d5dc561b6ad37ae012618074857054e..c021de59703d8e40920ebda189c84c8398863520 100644 (file)
 #include <boost/property_tree/ptree.hpp>
 #include <boost/filesystem.hpp>
 
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+
 #include "utils\texture_atlas.h"
 #include "utils\texture_font.h"
 
@@ -64,33 +68,59 @@ public:
 
 namespace caspar { namespace core {
        namespace text {
-               
+
+               using namespace boost::filesystem3;
+
                std::map<std::wstring, std::wstring> fonts;
-               
+
+               std::map<std::wstring, std::wstring> enumerate_fonts()
+               {
+                       std::map<std::wstring, std::wstring> result;
+
+                       FT_Library lib;
+                       FT_Error err = FT_Init_FreeType(&lib);
+                       if(err) 
+                               return result;
+
+                       auto fonts = directory_iterator(env::system_font_folder());
+                       auto end = directory_iterator();
+                       for(; fonts != end; ++fonts)
+                       {
+                               auto file = (*fonts);
+                               if(is_regular_file(file.path()))
+                               {
+                                       FT_Face face;
+                                       err = FT_New_Face(lib, u8(file.path().native()).c_str(), 0, &face);
+                                       if(err) 
+                                               continue;
+
+                                       const char* fontname = FT_Get_Postscript_Name(face);    //this doesn't work for .fon fonts. Ignoring those for now
+                                       if(fontname != nullptr)
+                                       {
+                                               std::string fontname_str(fontname);
+                                               result.insert(std::pair<std::wstring, std::wstring>(std::wstring(fontname_str.begin(), fontname_str.end()), file.path().native()));
+                                       }
+
+                                       FT_Done_Face(face);
+                               }
+                       }
+
+                       FT_Done_FreeType(lib);
+
+                       return result;
+               }
+
                void init()
                {
-                       fonts.swap(std::move(caspar::enumerate_fonts()));
+                       fonts.swap(std::move(enumerate_fonts()));
+                       if(fonts.size() > 0)
+                               register_producer_factory(&create_text_producer);
                }
 
                std::wstring find_font_file(const std::wstring& font_name)
                {
                        auto it = std::find_if(fonts.begin(), fonts.end(), font_comparer(font_name));
-                       if(it != fonts.end())
-                       {
-                               std::wstring filename = L"c:\\windows\\fonts\\" + (*it).second; //TODO: move font-folder setting to settings
-                               return filename;
-                       }
-       
-                       //try the default font
-                       it = std::find_if(fonts.begin(), fonts.end(), font_comparer(L"verdana"));       //TODO: move default-font to settings
-                       if(it != fonts.end())
-                       {
-                               std::wstring filename = L"c:\\windows\\fonts\\" + (*it).second; //TODO: move font-folder setting to settings
-                               return filename;
-                       }
-
-                       //fail
-                       return L"";
+                       return (it != fonts.end()) ? (*it).second : L"";
                }
        }
        
@@ -118,6 +148,7 @@ public:
                , atlas_(512,512,4)
                , font_(atlas_, text::find_font_file(text_info.font), text_info.size, !standalone)
        {
+               //TODO: examine str to determine which unicode_blocks to load
                font_.load_glyphs(text::Basic_Latin, text_info.color);
                font_.load_glyphs(text::Latin_1_Supplement, text_info.color);
                font_.load_glyphs(text::Latin_Extended_A, text_info.color);
index 453ba75808f5f0b5569c8c8541e95109b10376d7..5b264e6a37ec8463d053bf233c99da7b43f1c4df 100644 (file)
@@ -268,8 +268,13 @@ public:
                                if(bearingY > result.bearingY)
                                        result.bearingY = bearingY;
 
-                               if(coords.height > result.height)
-                                       result.height = coords.height;
+                               int protrudeUnderY = coords.height - bearingY;
+
+                               if (protrudeUnderY > result.protrudeUnderY)
+                                       result.protrudeUnderY = protrudeUnderY;
+
+                               if (result.bearingY + result.protrudeUnderY > result.height)
+                                        result.height = result.bearingY + result.protrudeUnderY;
 
                                pos_x += face_->glyph->advance.x / 64.0f;
                                previous = glyph_index;
index 567d622e47b0b9c4d1086ebb6b4c7822ede28429..8369c5d0fa17e22a65416ec6a8cd75cb457ac877 100644 (file)
@@ -180,6 +180,10 @@ public:
                        case 'Txt2':    //text engine data
                                break;
 
+                       case 'luni':
+                               name_ = stream.read_unicode_string();
+                               break;
+
                        case 'TySh':    //type tool object settings
                                read_text_data(stream);
                                break;
index 0a6f3e96850bf1559b412288f03fe4f4ea43d2ff..8af07fb207216d892c1a8dc2fa166a75bc96e090 100644 (file)
@@ -110,7 +110,6 @@ struct server::impl : boost::noncopyable
 
                register_producer_factory(&core::scene::create_dummy_scene_producer);
                register_producer_factory(&core::scene::create_xml_scene_producer);
-               register_producer_factory(&core::create_text_producer);
 
                setup_channels(env::properties());
                CASPAR_LOG(info) << L"Initialized channels.";