]> git.sesse.net Git - casparcg/commitdiff
* psd: added support for scaling and tracking in text-producer
authorniklaspandersson <niklas.p.andersson@svt.se>
Tue, 20 Aug 2013 12:12:20 +0000 (14:12 +0200)
committerniklaspandersson <niklas.p.andersson@svt.se>
Tue, 20 Aug 2013 12:12:20 +0000 (14:12 +0200)
core/core.vcxproj
core/core.vcxproj.filters
core/producer/text/text_producer.cpp
core/producer/text/text_producer.h
core/producer/text/utils/text_info.h [new file with mode: 0644]
core/producer/text/utils/texture_font.cpp
core/producer/text/utils/texture_font.h
modules/psd/psd_scene_producer.cpp

index 8b2286b54e81704f134eb09b1fea5fca2b990a7e..304d68e696773a8331781e242f5e806dbdfe250c 100644 (file)
     <ClInclude Include="producer\text\utils\string_metrics.h" />\r
     <ClInclude Include="producer\text\utils\texture_atlas.h" />\r
     <ClInclude Include="producer\text\utils\texture_font.h" />\r
+    <ClInclude Include="producer\text\utils\text_info.h" />\r
     <ClInclude Include="producer\variable.h" />\r
     <ClInclude Include="video_channel.h" />\r
     <ClInclude Include="consumer\output.h" />\r
index 15ca47fc6082f3c77d6fb96b682195327e9e2b95..a0d7356a5572efa2d28dd400659c88271159a515 100644 (file)
     <ClInclude Include="producer\variable.h">\r
       <Filter>source\producer</Filter>\r
     </ClInclude>\r
+    <ClInclude Include="producer\text\utils\text_info.h">\r
+      <Filter>source\producer\text\utils</Filter>\r
+    </ClInclude>\r
   </ItemGroup>\r
   <ItemGroup>\r
     <ClCompile Include="producer\transition\transition_producer.cpp">\r
index c021de59703d8e40920ebda189c84c8398863520..ccd3de4a00aaf85f813f97c372c959fb1f368d39 100644 (file)
@@ -117,10 +117,12 @@ namespace caspar { namespace core {
                                register_producer_factory(&create_text_producer);
                }
 
-               std::wstring find_font_file(const std::wstring& font_name)
+               text_info& find_font_file(text_info& info)
                {
+                       auto& font_name = info.font;
                        auto it = std::find_if(fonts.begin(), fonts.end(), font_comparer(font_name));
-                       return (it != fonts.end()) ? (*it).second : L"";
+                       info.font_file = (it != fonts.end()) ? (*it).second : L"";
+                       return info;
                }
        }
        
@@ -140,13 +142,13 @@ struct text_producer::impl
        text::texture_font font_;
 
 public:
-       explicit impl(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, const text::text_info& text_info, long parent_width, long parent_height, bool standalone) 
+       explicit impl(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, text::text_info& text_info, long parent_width, long parent_height, bool standalone) 
                : frame_factory_(frame_factory)
                , constraints_(parent_width, parent_height)
                , x_(x), y_(y), parent_width_(parent_width), parent_height_(parent_height)
                , standalone_(standalone)
                , atlas_(512,512,4)
-               , font_(atlas_, text::find_font_file(text_info.font), text_info.size, !standalone)
+               , font_(atlas_, text::find_font_file(text_info), !standalone)
        {
                //TODO: examine str to determine which unicode_blocks to load
                font_.load_glyphs(text::Basic_Latin, text_info.color);
@@ -241,7 +243,7 @@ public:
        }
 };
 
-text_producer::text_producer(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, const text::text_info& text_info, long parent_width, long parent_height, bool standalone)
+text_producer::text_producer(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, text::text_info& text_info, long parent_width, long parent_height, bool standalone)
        : impl_(new impl(frame_factory, x, y, str, text_info, parent_width, parent_height, standalone))
 {}
 
@@ -259,7 +261,7 @@ binding<std::wstring>& text_producer::text() { return impl_->text(); }
 const binding<int>& text_producer::current_bearing_y() const { return impl_->current_bearing_y(); }
 const binding<int>& text_producer::current_protrude_under_y() const { return impl_->current_protrude_under_y(); }
 
-spl::shared_ptr<text_producer> text_producer::create(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, const text::text_info& text_info, long parent_width, long parent_height, bool standalone)
+spl::shared_ptr<text_producer> text_producer::create(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, text::text_info& text_info, long parent_width, long parent_height, bool standalone)
 {
        return spl::make_shared<text_producer>(frame_factory, x, y, str, text_info, parent_width, parent_height, standalone);
 }
index 8d7e1cdbde8d913e45b217667b202761413d1883..15b14b45dfdf1e6256c980468260a849cf3d5a4f 100644 (file)
 
 #include "utils/color.h"
 #include "utils/string_metrics.h"
+#include "utils/text_info.h"
 
 namespace caspar { namespace core {
        namespace text 
        {
                void init();
-
-               struct text_info
-               {
-                       std::wstring font;
-                       float size;
-                       color<float> color;
-                       int baseline_shift;
-                       int tracking;
-               };
        }
 
 class text_producer : public frame_producer_base
 {
 public:
-       text_producer(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, const text::text_info& text_info, long parent_width, long parent_height, bool standalone);
-       static spl::shared_ptr<text_producer> create(const spl::shared_ptr<class frame_factory>& frame_factory, int x, int y, const std::wstring& str, const text::text_info& text_info, long parent_width, long parent_height, bool standalone = false);
+       text_producer(const spl::shared_ptr<frame_factory>& frame_factory, int x, int y, const std::wstring& str, text::text_info& text_info, long parent_width, long parent_height, bool standalone);
+       static spl::shared_ptr<text_producer> create(const spl::shared_ptr<class frame_factory>& frame_factory, int x, int y, const std::wstring& str, text::text_info& text_info, long parent_width, long parent_height, bool standalone = false);
        
        draw_frame receive_impl() override;
        boost::unique_future<std::wstring> call(const std::vector<std::wstring>& param) override;
diff --git a/core/producer/text/utils/text_info.h b/core/producer/text/utils/text_info.h
new file mode 100644 (file)
index 0000000..bc1ade0
--- /dev/null
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <string>
+#include "color.h"
+
+namespace caspar { namespace core { namespace text {
+
+       struct text_info
+       {
+               std::wstring font;
+               std::wstring font_file;
+
+               float size;
+               color<float> color;
+               int baseline_shift;
+               int tracking;
+       };
+
+}}}
\ No newline at end of file
index 5b264e6a37ec8463d053bf233c99da7b43f1c4df..6cd41263dca5be6c94493725cce30f34c7607a78 100644 (file)
@@ -44,11 +44,12 @@ private:
        FT_Face                 face_;
        texture_atlas   atlas_;
        float                   size_;
+       float                   tracking_;
        bool                    normalize_;
        std::map<int, glyph_info> glyphs_;
 
 public:
-       impl::impl(texture_atlas& atlas, const std::wstring& filename, float size, bool normalize_coordinates) : lib_(nullptr), face_(nullptr), atlas_(atlas), size_(size), normalize_(normalize_coordinates)
+       impl::impl(texture_atlas& atlas, const text_info& info, bool normalize_coordinates) : lib_(nullptr), face_(nullptr), atlas_(atlas), size_(info.size), tracking_(info.size*info.tracking/1000.0f), normalize_(normalize_coordinates)
        {
                try
                {
@@ -56,10 +57,10 @@ public:
                        err = FT_Init_FreeType(&lib_);
                        if(err) throw freetype_exception("Failed to initialize freetype");
 
-                       err = FT_New_Face(lib_, u8(filename).c_str(), 0, &face_);
+                       err = FT_New_Face(lib_, u8(info.font_file).c_str(), 0, &face_);
                        if(err) throw freetype_exception("Failed to load font");
 
-                       err = FT_Set_Char_Size(face_, (FT_F26Dot6)(size*64), 0, 72, 72);
+                       err = FT_Set_Char_Size(face_, static_cast<FT_F26Dot6>(size_*64), 0, 72, 72);
                        if(err) throw freetype_exception("Failed to set font size");
                }
                catch(std::exception& ex)
@@ -205,6 +206,7 @@ public:
                                        maxHeight = maxBearingY + maxProtrudeUnderY;
 
                                pos_x += face_->glyph->advance.x / 64.0f;
+                               pos_x += tracking_;
                                previous = glyph_index;
                        }
                        else
@@ -286,7 +288,7 @@ public:
        }
 }; 
 
-texture_font::texture_font(texture_atlas& atlas, const std::wstring& filename, float size, bool normalize_coordinates) : impl_(new impl(atlas, filename, size, normalize_coordinates)) {}
+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<float>& col) { impl_->load_glyphs(range, col); }
 std::vector<float> texture_font::create_vertex_stream(const std::wstring& str, int x, int y, int parent_width, int parent_height, string_metrics* metrics) { return impl_->create_vertex_stream(str, x, y, parent_width, parent_height, metrics); }
 string_metrics texture_font::measure_string(const std::wstring& str) { return impl_->measure_string(str); }
index e6acf8d72172fab8ea27f85d29db56d18fdc8467..8e977d34f2e98d34d9ddb798cf19e10c3e20b0eb 100644 (file)
@@ -5,6 +5,7 @@
 #include <common/memory.h>
 
 #include "string_metrics.h"
+#include "text_info.h"
 
 namespace caspar { namespace core { namespace text {
 
@@ -18,7 +19,7 @@ class texture_font
        const texture_font& operator=(const texture_font&);
 
 public:
-       texture_font(texture_atlas&, const std::wstring& filename, float size, bool normalize_coordinates);
+       texture_font(texture_atlas&, const text_info&, bool normalize_coordinates);
        void load_glyphs(unicode_block block, const color<float>& col);
        std::vector<float> create_vertex_stream(const std::wstring& str, int x, int y, int parent_width, int parent_height, string_metrics* metrics);
        string_metrics measure_string(const std::wstring& str);
index 59e67b288448d1c155f1a4bc0176e6d200417f7d..3e0a50e0dab666f3e3ac3f1561689e6da0cfefbb 100644 (file)
@@ -312,7 +312,7 @@ spl::shared_ptr<core::frame_producer> create_psd_scene_producer(const spl::share
        {
                if((*it)->is_visible())
                {
-                       if((*it)->is_text())
+                       if((*it)->is_text() && (*it)->sheet_color() == 4)
                        {
                                std::wstring str = (*it)->text_data().get(L"EngineDict.Editor.Text", L"");