freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Problem on render 'j' on non-monospace font face.


From: suzuki toshiya
Subject: Re: [ft] Problem on render 'j' on non-monospace font face.
Date: Thu, 06 Mar 2014 15:36:54 +0900
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130518 Icedove/17.0.5

Hi,

I could reproduce the problem by your testing code,
but yet I'm not sure if this is FreeType2 problem.
Because,

1) if I use "ftstring" included in freetype2-demos
(you can use your own testing text, although the
default text is "brown fox...".)

2) if I execute your program with bigger glyph size
(e.g. height=128 etc), my impression on the "bug dot"
at the lower-right corner of "j" is looking like a
clipped overflow from the lower-left end of "j".
If I look very carefully, the lower-left end of "j"
is not connected smoothly, it seems as if there is
a crack.

Could you check more detail on the code copying
the bitmap image from FreeType2 to OpenCV?

# Yet I've not checked your code at all.

Regards,
mpsuzuki

On 03/06/2014 03:03 PM, 昌霖 wrote:
> Hi everyone,
> 
>    I am new for freetype library, and trying to following the tutorial to 
> render text into opencv mat.
>    And I have some problem on non-monospace font face like Ubuntu Regular.
>    Following is my testing code and it can also be downloaded from my dropbox 
> page.
> https://www.dropbox.com/sh/qp93w5fzcu9hbcq/VSABZHiNV1
>    That page include my testing code, render output, and test font face.
>    You can compile it by using the following command:
>    "g++ -o test_ubuntu_regular test_freetype.cpp `pkg-config opencv --cflags 
> --libs` -I/usr/include/freetype2 -lfreetype"
>    "g++ -o test_ubuntu_regular_mono test_freetype.cpp `pkg-config opencv 
> --cflags --libs` -I/usr/include/freetype2 -lfreetype -D_USE_MONO_"
>    I also try to use kerning to solve the problem but the delta vector always 
> return (0,0).
> 
> Thanks for yours kindly help.
> Changlin
> 
> ==========================================================================================
> #include <string>
> #include <iostream>
> #include <opencv2/core/core.hpp>
> #include <opencv2/imgproc/imgproc.hpp>
> #include <opencv2/highgui/highgui.hpp>
> #include <ft2build.h>
> #include FT_FREETYPE_H
> 
> using namespace std;
> using namespace cv;
> 
> int main(int arch, char* argv[])
> {
>      ///Setup test font, font size, and string
> #ifndef _USE_MONO_
>      string test_font = "Ubuntu-R.ttf";
> #else
>      string test_font = "UbuntuMono-R.ttf";
> #endif
>      string test_string = "jjj abcdefghijklmnopqrstuvwxyz jjj";
>      int height = 32;
> 
>      FT_UInt status;
>      ///Initialize library
>      FT_Library library;
>      status = FT_Init_FreeType(&library);
>      if (status)
>      {
>          cout<<"Freetype library initialization failed"<<endl;
>          return 1;
>      }
>      ///Load font face
>      FT_Face face;
>      status = FT_New_Face(library, test_font.c_str(), 0, &face);
>      if (status)
>      {
>          cout<<"Freetype load font face failed"<<endl;
>          return 1;
>      }
>      ///Set font size
>      status = FT_Set_Pixel_Sizes(face, 0, height);
>      if (status)
>      {
>          cout<<"Freetype set size failed"<<endl;
>          return 1;
>      }
>      ///Render to text_image
>      Mat text_image;
>      int max_height=0;
>      FT_GlyphSlot slot=face->glyph;
>      for (size_t t=0; t<test_string.size(); t++)
>      {
>          ///Load and render character
>          status = FT_Load_Char(face, test_string[t], FT_LOAD_RENDER );
>          if (status)
>          {
>              cout<<"Freetype load char \""<<test_string[t]<<"\" failed"<<endl;
>              continue;
>          }
>          ///Compute max height of character image for concat them
>          max_height = max(max_height, 
> height-slot->bitmap_top+slot->bitmap.rows);
>          ///Create character image
>          Mat char_image=Mat::zeros(max_height, slot->advance.x/64, CV_8UC1);
>          for (int y=height-slot->bitmap_top, j=0; j<slot->bitmap.rows; y++, 
> j++)
>          {
>              uchar* scanline = char_image.ptr<uchar>(y);
>              for (int x=slot->bitmap_left, i=0; i<slot->bitmap.width; x++, 
> i++)
>              {
>                  if (x>=char_image.cols)
>                  {
>                      continue;
>                  }
>                  scanline[x] |= slot->bitmap.buffer[j*slot->bitmap.pitch+i];
>              }
>          }
>          ///Concat character image to text image
>          if (text_image.empty())
>          {
>              text_image=char_image;
>          }
>          else
>          {
>              if (max_height>text_image.rows)
>              {
>                  copyMakeBorder(text_image, text_image, 0, 
> max_height-text_image.rows, 0, 0, BORDER_CONSTANT, Scalar(0));
>              }
>              hconcat(text_image, char_image, text_image);
>          }
>      }
> 
> #ifndef _USE_MONO_
>      imwrite("ubuntu-regular.png", text_image);
> #else
>      imwrite("ubuntu-regular-mono.png", text_image);
> #endif
> }
> ==============================================================================================
> 
> 
> _______________________________________________
> Freetype mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/freetype
> 

Attachment: mps20140306a.png
Description: PNG image


reply via email to

[Prev in Thread] Current Thread [Next in Thread]