]> git.sesse.net Git - casparcg/commitdiff
[text_producer] Made it easier to see what fonts are missing when loading a PSD.
authorHelge Norberg <helge.norberg@svt.se>
Thu, 9 Mar 2017 16:29:35 +0000 (17:29 +0100)
committerHelge Norberg <helge.norberg@svt.se>
Thu, 9 Mar 2017 16:29:35 +0000 (17:29 +0100)
core/producer/text/utils/freetype_library.cpp
core/producer/text/utils/freetype_library.h
core/producer/text/utils/texture_font.cpp

index b71ec20dcd7cfa936b0389b16bc2011fc8e15cd9..1eb1cc137dc86989a40c9e7952f3e53818fa9f50 100644 (file)
@@ -48,8 +48,12 @@ spl::shared_ptr<std::remove_pointer<FT_Library>::type> get_lib_for_thread()
        return *result;
 }
 
-spl::shared_ptr<std::remove_pointer<FT_Face>::type> get_new_face(const std::string& font_file)
+spl::shared_ptr<std::remove_pointer<FT_Face>::type> get_new_face(
+               const std::string& font_file, const std::string& font_name)
 {
+       if (font_file.empty())
+               CASPAR_THROW_EXCEPTION(expected_freetype_exception() << msg_info("Failed to find font file for \"" + font_name + "\""));
+
        auto lib = get_lib_for_thread();
        FT_Face face;
        if (FT_New_Face(lib.get(), u8(font_file).c_str(), 0, &face))
index 92fa5bddaa4cd7acf96a3bf55e2833e1def6b9e3..fe33fbda62b3ff0d2350e6f6ad6f27ff81b370a6 100644 (file)
@@ -33,8 +33,9 @@
 namespace caspar { namespace core { namespace text {
 
 struct freetype_exception : virtual caspar_exception { };
+struct expected_freetype_exception : virtual user_error { };
 
 spl::shared_ptr<std::remove_pointer<FT_Library>::type> get_lib_for_thread();
-spl::shared_ptr<std::remove_pointer<FT_Face>::type> get_new_face(const std::string& font_file);
+spl::shared_ptr<std::remove_pointer<FT_Face>::type> get_new_face(const std::string& font_file, const std::string& font_name = "");
 
 }}}
index 541f0e430b074fca76303598da91f20934e6de6e..ae38582131d756eefd6aef00f84dcab52ebe51a4 100644 (file)
@@ -46,7 +46,7 @@ private:
 
 public:
        impl(texture_atlas& atlas, const text_info& info, bool normalize_coordinates)
-               : face_(get_new_face(u8(info.font_file)))
+               : face_(get_new_face(u8(info.font_file), u8(info.font)))
                , atlas_(atlas)
                , size_(info.size)
                , tracking_(info.size*info.tracking/1000.0)
@@ -54,7 +54,7 @@ public:
                , name_(info.font)
        {
                if (FT_Set_Char_Size(face_.get(), static_cast<FT_F26Dot6>(size_*64), 0, 72, 72))
-                       CASPAR_THROW_EXCEPTION(freetype_exception() << msg_info("Failed to set font size"));
+                       CASPAR_THROW_EXCEPTION(expected_freetype_exception() << msg_info("Failed to set font size"));
        }
 
        void set_tracking(int tracking)
@@ -63,7 +63,7 @@ public:
        }
 
        int count_glyphs_in_range(unicode_block block)
-       { 
+       {
                unicode_range range = get_range(block);
 
                //TODO: extract info from freetype
@@ -82,7 +82,7 @@ public:
                        FT_UInt glyph_index = FT_Get_Char_Index(face_.get(), i);
                        if(!glyph_index)        //ignore codes that doesn't have a glyph for now. Might want to map these to a special glyph later.
                                continue;
-                       
+
                        FT_Error err = FT_Load_Glyph(face_.get(), glyph_index, flags);
                        if(err) continue;       //igonore glyphs that fail to load
 
@@ -97,7 +97,7 @@ public:
                        }
 
                        atlas_.set_region(region.x, region.y, bitmap.width, bitmap.rows, bitmap.buffer, bitmap.pitch, col);
-                       glyphs_.insert(std::pair<int, glyph_info>(i, glyph_info(bitmap.width, bitmap.rows, 
+                       glyphs_.insert(std::pair<int, glyph_info>(i, glyph_info(bitmap.width, bitmap.rows,
                                                                                region.x / static_cast<double>(atlas_.width()),
                                                                                region.y / static_cast<double>(atlas_.height()),
                                                                                (region.x + bitmap.width) / static_cast<double>(atlas_.width()),
@@ -126,7 +126,7 @@ public:
                {
                        auto glyph_it = glyphs_.find(*it);
                        if (glyph_it != glyphs_.end())
-                       {       
+                       {
                                const glyph_info& coords = glyph_it->second;
 
                                FT_UInt glyph_index = FT_Get_Char_Index(face_.get(), (*it));
@@ -224,7 +224,7 @@ public:
        string_metrics measure_string(const std::wstring& str)
        {
                string_metrics result;
-               
+
                bool use_kerning = (face_->face_flags & FT_FACE_FLAG_KERNING) == FT_FACE_FLAG_KERNING;
                int index = 0;
                FT_UInt previous = 0;
@@ -236,7 +236,7 @@ public:
                {
                        auto glyph_it = glyphs_.find(*it);
                        if(glyph_it != glyphs_.end())
-                       {       
+                       {
                                const glyph_info& coords = glyph_it->second;
 
                                FT_UInt glyph_index = FT_Get_Char_Index(face_.get(), (*it));
@@ -281,7 +281,7 @@ public:
        {
                return size_;
        }
-}; 
+};
 
 texture_font::texture_font(texture_atlas& atlas, const text_info& info, bool normalize_coordinates) : impl_(new impl(atlas, info, normalize_coordinates)) {}
 void texture_font::load_glyphs(unicode_block range, const color<double>& col) { impl_->load_glyphs(range, col); }