]> git.sesse.net Git - casparcg/commitdiff
Additional font metrics and correct height calculation
authorHelge Norberg <helge.norberg@svt.se>
Tue, 13 Aug 2013 09:24:58 +0000 (11:24 +0200)
committerHelge Norberg <helge.norberg@svt.se>
Tue, 13 Aug 2013 09:24:58 +0000 (11:24 +0200)
core/producer/text/text_producer.cpp
core/producer/text/text_producer.h
core/producer/text/utils/string_metrics.h
core/producer/text/utils/texture_font.cpp

index a72ba5cb741853fe28d050353aa1f33357c503fe..6da1507b2d5dc561b6ad37ae012618074857054e 100644 (file)
@@ -103,6 +103,8 @@ struct text_producer::impl
        bool standalone_;
        binding<std::wstring> text_;
        std::shared_ptr<void> text_subscription_;
+       binding<int> current_bearing_y_;
+       binding<int> current_protrude_under_y_;
        draw_frame frame_;
        text::texture_atlas atlas_;
        text::texture_font font_;
@@ -144,6 +146,8 @@ public:
 
                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);
                frame_ = core::draw_frame(std::move(frame));
        }
 
@@ -176,6 +180,16 @@ public:
        {
                return text_;
        }
+
+       const binding<int>& current_bearing_y() const
+       {
+               return current_bearing_y_;
+       }
+
+       const binding<int>& current_protrude_under_y() const
+       {
+               return current_protrude_under_y_;
+       }
        
        std::wstring print() const
        {
@@ -211,6 +225,8 @@ boost::property_tree::wptree text_producer::info() const { return impl_->info();
 void text_producer::subscribe(const monitor::observable::observer_ptr& o) {}
 void text_producer::unsubscribe(const monitor::observable::observer_ptr& o) {}
 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)
 {
index d97d415f03b11ed91f71c7bac7a5c7011f1161db..55ea42f4538f2a327702f5936a7425d379b80dfc 100644 (file)
@@ -64,6 +64,8 @@ public:
        void unsubscribe(const monitor::observable::observer_ptr& o) override;
 
        binding<std::wstring>& text();
+       const binding<int>& current_bearing_y() const;
+       const binding<int>& current_protrude_under_y() const;
 private:
        struct impl;
        spl::unique_ptr<impl> impl_;
index f0f9fa3762ffa7c9d9a01ed84e13a4f91b033ecc..3077dd00ff1af5f63cd09ccefd7b9570a6c15ee2 100644 (file)
@@ -7,6 +7,7 @@ namespace caspar { namespace core { namespace text {
                string_metrics() : width(0), bearingY(0), height(0) {}
                int width;
                int bearingY;
+               int protrudeUnderY;
                int height;
        };
 }}}
\ No newline at end of file
index e11973a4eec6e3982f317ad1adccbd3466273760..453ba75808f5f0b5569c8c8541e95109b10376d7 100644 (file)
@@ -138,6 +138,7 @@ public:
                float pos_y = (float)y;
 
                int maxBearingY = 0;
+               int maxProtrudeUnderY = 0;
                int maxHeight = 0;
 
                auto end = str.end();
@@ -191,11 +192,17 @@ public:
                                result[index*16 + 15] = coords.bottom;  //texcoord.s
 
                                int bearingY = face_->glyph->metrics.horiBearingY >> 6;
+
                                if(bearingY > maxBearingY)
                                        maxBearingY = bearingY;
 
-                               if(coords.height > maxHeight)
-                                       maxHeight = coords.height;
+                               int protrudeUnderY = coords.height - bearingY;
+
+                               if (protrudeUnderY > maxProtrudeUnderY)
+                                       maxProtrudeUnderY = protrudeUnderY;
+
+                               if (maxBearingY + maxProtrudeUnderY > maxHeight)
+                                       maxHeight = maxBearingY + maxProtrudeUnderY;
 
                                pos_x += face_->glyph->advance.x / 64.0f;
                                previous = glyph_index;
@@ -222,6 +229,7 @@ public:
                        metrics->width = (int)(pos_x - x + 0.5f);
                        metrics->bearingY = maxBearingY;
                        metrics->height = maxHeight;
+                       metrics->protrudeUnderY = maxProtrudeUnderY;
                }
                return result;
        }