]> git.sesse.net Git - casparcg/commitdiff
Merge branch '2.1.0' of https://github.com/CasparCG/Server into 2.1.0
authorHelge Norberg <helge.norberg@svt.se>
Fri, 23 Aug 2013 20:10:28 +0000 (22:10 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Fri, 23 Aug 2013 20:10:28 +0000 (22:10 +0200)
Conflicts:
core/core.vcxproj.filters

1  2 
core/core.vcxproj
core/core.vcxproj.filters
core/producer/text/text_producer.cpp
core/producer/text/text_producer.h

diff --combined core/core.vcxproj
index e58bf843291eb9d4ce50739f4d2fec513c543390,304d68e696773a8331781e242f5e806dbdfe250c..feeb25c42a873773db1e60bd4054c43b3792111e
      <ClInclude Include="producer\binding.h" />\r
      <ClInclude Include="producer\draw\freehand_producer.h" />\r
      <ClInclude Include="producer\scene\const_producer.h" />\r
 +    <ClInclude Include="producer\scene\expression_parser.h" />\r
      <ClInclude Include="producer\scene\hotswap_producer.h" />\r
      <ClInclude Include="producer\scene\scene_producer.h" />\r
      <ClInclude Include="producer\scene\xml_scene_producer.h" />\r
      <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
        <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
        <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
      </ClCompile>\r
 +    <ClCompile Include="producer\scene\expression_parser.cpp">\r
 +      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
 +      <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
 +    </ClCompile>\r
      <ClCompile Include="producer\scene\hotswap_producer.cpp">\r
        <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
        <PrecompiledHeaderFile Condition="'$(Configuration)|$(Platform)'=='Release|x64'">../../StdAfx.h</PrecompiledHeaderFile>\r
index 83dc27134915a221d06b1eab38e4eca32a6dc35a,a0d7356a5572efa2d28dd400659c88271159a515..788d617cfb4156bbac355b1855cc314c595a1c8e
      <ClInclude Include="producer\variable.h">\r
        <Filter>source\producer</Filter>\r
      </ClInclude>\r
 +    <ClInclude Include="producer\scene\expression_parser.h">\r
 +      <Filter>source\producer\scene</Filter>\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\scene\xml_scene_producer.cpp">\r
        <Filter>source\producer\scene</Filter>\r
      </ClCompile>\r
 +    <ClCompile Include="producer\scene\expression_parser.cpp">\r
 +      <Filter>source\producer\scene</Filter>\r
 +    </ClCompile>\r
    </ItemGroup>\r
  </Project>
index 18669fc62c269ff4469eda661c9a9cb79ee44cfa,ccd3de4a00aaf85f813f97c372c959fb1f368d39..7389a48c266a6c7d322fca27d721265115a6b947
@@@ -25,7 -25,6 +25,7 @@@
  
  #include <core/producer/frame_producer.h>
  #include <core/producer/color/color_producer.h>
 +#include <core/producer/variable.h>
  #include <core/frame/geometry.h>
  #include <core/frame/frame.h>
  #include <core/frame/draw_frame.h>
@@@ -118,10 -117,12 +118,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;
                }
        }
        
@@@ -132,40 -133,35 +134,40 @@@ struct text_producer::imp
        constraints constraints_;
        int x_, y_, parent_width_, parent_height_;
        bool standalone_;
 -      binding<std::wstring> text_;
 +      variable_impl<std::wstring> text_;
        std::shared_ptr<void> text_subscription_;
 -      binding<int> current_bearing_y_;
 -      binding<int> current_protrude_under_y_;
 +      variable_impl<int> current_bearing_y_;
 +      variable_impl<int> current_protrude_under_y_;
        draw_frame frame_;
        text::texture_atlas atlas_;
        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);
                font_.load_glyphs(text::Latin_1_Supplement, text_info.color);
                font_.load_glyphs(text::Latin_Extended_A, text_info.color);
  
 -              text_subscription_ = text_.on_change([this]()
 +              text_subscription_ = text_.value().on_change([this]()
                {
 -                      generate_frame(text_.get());
 +                      generate_frame(text_.value().get());
                });
  
 +              constraints_.height.depend_on(text());
 +              constraints_.width.depend_on(text());
 +              current_bearing_y_.as<int>().depend_on(text());
 +              current_protrude_under_y_.as<int>().depend_on(text());
 +
                //generate frame
 -              text_.set(str);
 +              text_.value().set(str);
  
                CASPAR_LOG(info) << print() << L" Initialized";
        }
  
                this->constraints_.width.set(metrics.width);
                this->constraints_.height.set(metrics.height);
 -              current_bearing_y_.set(metrics.bearingY);
 -              current_protrude_under_y_.set(metrics.protrudeUnderY);
 +              current_bearing_y_.value().set(metrics.bearingY);
 +              current_protrude_under_y_.value().set(metrics.protrudeUnderY);
                frame_ = core::draw_frame(std::move(frame));
 +              frame_.transform().image_transform.fill_translation[1] = static_cast<double>(metrics.bearingY) / static_cast<double>(metrics.height);
        }
  
        text::string_metrics measure_string(const std::wstring& str)
        boost::unique_future<std::wstring> call(const std::vector<std::wstring>& param)
        {
                std::wstring result;
 -              text_.set(param.empty() ? L"" : param[0]);
 +              text_.value().set(param.empty() ? L"" : param[0]);
  
                return async(launch::deferred, [=]{return result;});
        }
  
 +      variable& get_variable(const std::wstring& name)
 +      {
 +              if (name == L"text")
 +                      return text_;
 +              else if (name == L"current_bearing_y")
 +                      return current_bearing_y_;
 +              else if (name == L"current_protrude_under_y")
 +                      return current_protrude_under_y_;
 +
 +              CASPAR_THROW_EXCEPTION(caspar_exception() << msg_info(L"text_producer does not have a variable called " + name));
 +      }
 +
 +      const std::vector<std::wstring>& get_variables() const
 +      {
 +              static std::vector<std::wstring> vars =
 +                              boost::assign::list_of<std::wstring>
 +                                              (L"text")
 +                                              (L"current_bearing_y")
 +                                              (L"current_protrude_under_y");
 +
 +              return vars;
 +      }
 +
        constraints& pixel_constraints()
        {
                return constraints_;
  
        binding<std::wstring>& text()
        {
 -              return text_;
 +              return text_.value();
        }
  
        const binding<int>& current_bearing_y() const
        {
 -              return current_bearing_y_;
 +              return current_bearing_y_.value();
        }
  
        const binding<int>& current_protrude_under_y() const
        {
 -              return current_protrude_under_y_;
 +              return current_protrude_under_y_.value();
        }
        
        std::wstring print() const
        {
 -              return L"text[" + text_.get() + L"]";
 +              return L"text[" + text_.value().get() + L"]";
        }
  
        std::wstring name() const
        {
                boost::property_tree::wptree info;
                info.add(L"type", L"text");
 -              info.add(L"text", text_.get());
 +              info.add(L"text", text_.value().get());
                return info;
        }
  };
  
- 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))
  {}
  
  draw_frame text_producer::receive_impl() { return impl_->receive_impl(); }
  boost::unique_future<std::wstring> text_producer::call(const std::vector<std::wstring>& param) { return impl_->call(param); }
 +variable& text_producer::get_variable(const std::wstring& name) { return impl_->get_variable(name); }
 +const std::vector<std::wstring>& text_producer::get_variables() const { return impl_->get_variables(); }
  text::string_metrics text_producer::measure_string(const std::wstring& str) { return impl_->measure_string(str); }
  
  constraints& text_producer::pixel_constraints() { return impl_->pixel_constraints(); }
@@@ -291,7 -261,7 +293,7 @@@ binding<std::wstring>& text_producer::t
  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);
  }
@@@ -317,9 -287,7 +319,9 @@@ spl::shared_ptr<frame_producer> create_
        try_get_color(col_str, col_val);
        text_info.color = core::text::color<float>(col_val);
  
 -      return text_producer::create(frame_factory, x, y, params.at(1), text_info, format_desc.width, format_desc.height, true);
 +      bool standalone = get_param(L"STANDALONE", params, false);
 +
 +      return text_producer::create(frame_factory, x, y, params.at(1), text_info, format_desc.width, format_desc.height, standalone);
  }
  
  }}
index 022e1be24582faf808d15bc27e266b1110ffbe89,15b14b45dfdf1e6256c980468260a849cf3d5a4f..d0a3f9c4dea414862e821f85614bdf6dbe70a1ed
  
  #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;
-               };
        }
  
  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;
 +      variable& get_variable(const std::wstring& name) override;
 +      const std::vector<std::wstring>& get_variables() const override;
  
        text::string_metrics measure_string(const std::wstring& str);