opencv::prelude

Trait FreeType2Trait

Source
pub trait FreeType2Trait: AlgorithmTrait + FreeType2TraitConst {
    // Required method
    fn as_raw_mut_FreeType2(&mut self) -> *mut c_void;

    // Provided methods
    fn load_font_data(&mut self, font_file_name: &str, idx: i32) -> Result<()> { ... }
    unsafe fn load_font_data_1(
        &mut self,
        p_buf: *mut c_char,
        buf_size: size_t,
        idx: i32,
    ) -> Result<()> { ... }
    fn set_split_number(&mut self, num: i32) -> Result<()> { ... }
    fn put_text(
        &mut self,
        img: &mut impl ToInputOutputArray,
        text: &str,
        org: Point,
        font_height: i32,
        color: Scalar,
        thickness: i32,
        line_type: i32,
        bottom_left_origin: bool,
    ) -> Result<()> { ... }
    fn get_text_size(
        &mut self,
        text: &str,
        font_height: i32,
        thickness: i32,
        base_line: &mut i32,
    ) -> Result<Size> { ... }
}
Expand description

Mutable methods for crate::freetype::FreeType2

Required Methods§

Provided Methods§

Source

fn load_font_data(&mut self, font_file_name: &str, idx: i32) -> Result<()>

Load font data.

The function loadFontData loads font data from file.

§Parameters
  • fontFileName: FontFile Name
  • idx: face_index to select a font faces in a single file.
Source

unsafe fn load_font_data_1( &mut self, p_buf: *mut c_char, buf_size: size_t, idx: i32, ) -> Result<()>

Load font data.

The function loadFontData loads font data from memory. The data is not copied, the user needs to make sure the data lives at least as long as FreeType2. After the FreeType2 object is destroyed, the buffer can be safely deallocated.

§Parameters
  • pBuf: pointer to buffer containing font data
  • bufSize: size of buffer
  • idx: face_index to select a font faces in a single file.
Source

fn set_split_number(&mut self, num: i32) -> Result<()>

Set Split Number from Bezier-curve to line

The function setSplitNumber set the number of split points from bezier-curve to line. If you want to draw large glyph, large is better. If you want to draw small glyph, small is better.

§Parameters
  • num: number of split points from bezier-curve to line
Source

fn put_text( &mut self, img: &mut impl ToInputOutputArray, text: &str, org: Point, font_height: i32, color: Scalar, thickness: i32, line_type: i32, bottom_left_origin: bool, ) -> Result<()>

Draws a text string.

The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by “Tofu” or non-drawn.

§Parameters
  • img: Image. (Only 8UC1/8UC3/8UC4 2D mat is supported.)
  • text: Text string to be drawn.
  • org: Bottom-left/Top-left corner of the text string in the image.
  • fontHeight: Drawing font size by pixel unit.
  • color: Text color.
  • thickness: Thickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness.
  • line_type: Line type. See the line for details.
  • bottomLeftOrigin: When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner.
Source

fn get_text_size( &mut self, text: &str, font_height: i32, thickness: i32, base_line: &mut i32, ) -> Result<Size>

Calculates the width and height of a text string.

The function getTextSize calculates and returns the approximate size of a box that contains the specified text. That is, the following code renders some text, the tight box surrounding it, and the baseline: :

   String text = "Funny text inside the box";
   int fontHeight = 60;
   int thickness = -1;
   int linestyle = LINE_8;

   Mat img(600, 800, CV_8UC3, Scalar::all(0));

   int baseline=0;

   cv::Ptr<cv::freetype::FreeType2> ft2;
   ft2 = cv::freetype::createFreeType2();
   ft2->loadFontData( "./mplus-1p-regular.ttf", 0 );

   Size textSize = ft2->getTextSize(text,
                                     fontHeight,
                                     thickness,
                                     &baseline);

   if(thickness > 0){
       baseline += thickness;
   }

   // center the text
   Point textOrg((img.cols - textSize.width) / 2,
                  (img.rows + textSize.height) / 2);

   // draw the box
   rectangle(img, textOrg + Point(0, baseline),
              textOrg + Point(textSize.width, -textSize.height),
              Scalar(0,255,0),1,8);

   // ... and the baseline first
   line(img, textOrg + Point(0, thickness),
         textOrg + Point(textSize.width, thickness),
         Scalar(0, 0, 255),1,8);

   // then put the text itself
   ft2->putText(img, text, textOrg, fontHeight,
                 Scalar::all(255), thickness, linestyle, true );
§Parameters
  • text: Input text string.
  • fontHeight: Drawing font size by pixel unit.
  • thickness: Thickness of lines used to render the text. See putText for details.
  • baseLine:[out] y-coordinate of the baseline relative to the bottom-most text point.
§Returns

The size of a box that contains the specified text.

§See also

cv::putText

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§