]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7515: txt len
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 1 May 2015 03:11:12 +0000 (22:11 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:28 +0000 (12:47 -0500)
src/include/switch_core_video.h
src/mod/applications/mod_cv/mod_cv.cpp
src/switch_core_video.c

index bbe1b6e1f3b46c5c41c775aeec7401a4309886c5..ef7c9e216b87b928751d5d9a36f5a24228862116 100644 (file)
@@ -325,10 +325,10 @@ SWITCH_DECLARE(void) switch_img_txt_handle_destroy(switch_img_txt_handle_t **han
 * \param[in]    angle       Angle to rotate
 */
 
-SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img,
-                                                                                                                        int x, int y, const char *text,
-                                                                                                                        const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle);
-
+SWITCH_DECLARE(uint32_t) switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img,
+                                                                                                         int x, int y, const char *text,
+                                                                                                         const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle);
+                                                
 
 SWITCH_DECLARE(void) switch_img_patch_hole(switch_image_t *IMG, switch_image_t *img, int x, int y, switch_image_rect_t *rect);
 
index 4baad69194f8b51de3cf600a5fd20c8dbbabf83e..50dd5862b4d51d12d9e899743724137bccd77178 100644 (file)
@@ -198,18 +198,25 @@ static void context_render_text(cv_context_t *context, struct overlay *overlay,
 
     if (len < 5) len = 5;
 
-    width = (int) (float)(font_size * .95f * len);
+    //width = (int) (float)(font_size * .95f * len);
 
     switch_color_set_rgb(&bgcolor, overlay->bg);
 
+
+
+    switch_img_txt_handle_destroy(&overlay->txthandle);
+    switch_img_txt_handle_create(&overlay->txthandle, overlay->font_face, overlay->fg, overlay->bg, font_size, 0, NULL);
+
+    width = switch_img_txt_handle_render(overlay->txthandle,
+                                                                                NULL,
+                                                                                font_size / 2, font_size / 2,
+                                                                                text, NULL, overlay->fg, overlay->bg, 0, 0);
+
     if (!overlay->png || (overlay->png->d_w != width || overlay->png->d_h != font_size * 2)) {
         switch_img_free(&overlay->png);
         overlay->png = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1);
     }
 
-    switch_img_txt_handle_destroy(&overlay->txthandle);
-    switch_img_txt_handle_create(&overlay->txthandle, overlay->font_face, overlay->fg, overlay->bg, font_size, 0, NULL);
-
 
     switch_img_fill(overlay->png, 0, 0, overlay->png->d_w, overlay->png->d_h, &bgcolor);
     switch_img_txt_handle_render(overlay->txthandle,
index 63d02dff3bb93d46148a2f6a0d18ed229717ab90..9a21d84802123d4f04eb8127687e3a18818a6f54 100644 (file)
@@ -681,9 +681,10 @@ static void draw_bitmap(switch_img_txt_handle_t *handle, switch_image_t *img, FT
 #endif
 
 
-SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img,
+SWITCH_DECLARE(uint32_t) switch_img_txt_handle_render(switch_img_txt_handle_t *handle, switch_image_t *img,
                                                                                                                         int x, int y, const char *text,
-                                                                                                                        const char *font_family, const char *font_color, const char *bgcolor, uint16_t font_size, double angle)
+                                                                                                                        const char *font_family, const char *font_color, 
+                                                                                                                        const char *bgcolor, uint16_t font_size, double angle)
 {
 #if SWITCH_HAVE_FREETYPE
        FT_GlyphSlot  slot;
@@ -694,9 +695,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_hand
        int           index = 0;
        FT_ULong      ch;
        FT_Face face;
+       uint32_t width = 0;
+       int this_x = 0, last_x = 0, space = 0;
 
-       if (zstr(text)) return SWITCH_STATUS_FALSE;
-       switch_assert(img->fmt == SWITCH_IMG_FMT_I420);
+       if (zstr(text)) return 0;
+
+       switch_assert(!img || img->fmt == SWITCH_IMG_FMT_I420);
 
        if (font_family) {
                handle->font_family = switch_core_strdup(handle->pool, font_family);
@@ -730,12 +734,12 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_hand
        error = FT_New_Face(handle->library, font_family, 0, &face); /* create face object */
        if (error) {
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to open font %s\n", font_family);
-               return SWITCH_STATUS_FALSE;
+               return 0;
        }
 
        /* use 50pt at 100dpi */
        error = FT_Set_Char_Size(face, 64 * font_size, 0, 96, 96); /* set character size */
-       if (error) return SWITCH_STATUS_FALSE;
+       if (error) return 0;
 
        slot = face->glyph;
 
@@ -766,10 +770,25 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_hand
 
                /* load glyph image into the slot (erase previous one) */
                error = FT_Load_Char(face, ch, FT_LOAD_RENDER);
+
                if (error) continue;
 
-               /* now, draw to our target surface (convert position) */
-               draw_bitmap(handle, img, &slot->bitmap, pen.x + slot->bitmap_left, pen.y - slot->bitmap_top + font_size);
+               this_x = pen.x + slot->bitmap_left;
+               
+               if (img) {
+                       /* now, draw to our target surface (convert position) */
+                       draw_bitmap(handle, img, &slot->bitmap, this_x, pen.y - slot->bitmap_top + font_size);
+               }
+
+               if (last_x) {
+                       space = this_x - last_x;
+               } else {
+                       space = 0;
+               }
+
+               last_x = this_x;
+
+               width += space;
 
                /* increment pen position */
                pen.x += slot->advance.x >> 6;
@@ -778,9 +797,9 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_hand
 
        FT_Done_Face(face);
 
-       return SWITCH_STATUS_SUCCESS;
+       return width + slot->bitmap.width * 3;
 #else
-       return SWITCH_STATUS_FALSE;
+       return 0;
 #endif
 }
 
@@ -836,13 +855,16 @@ SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const c
 
     if (len < 5) len = 5;
 
-    width = (int) (float)(font_size * 0.75f * len);
-       
-       txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1);
-
        switch_img_txt_handle_create(&txthandle, font_face, fg, bg, font_size, 0, NULL);
        switch_color_set_rgb(&bgcolor, bg);
+
+    width = switch_img_txt_handle_render(txthandle,
+                                                                                NULL,
+                                                                                font_size / 2, font_size / 2,
+                                                                                txt, NULL, fg, bg, 0, 0);
        
+       txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1);
+
     switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor);
     switch_img_txt_handle_render(txthandle,
                                  txtimg,