tordex / cairo

Cairo 2D graphics library. Sources and windows binaries.
8 stars 3 forks source link

unresolved external symbol cairo_ft_fony_face_create_for_ft #1

Open Prakash19921206 opened 8 years ago

Prakash19921206 commented 8 years ago

i think this build is not compiled with freetype library. i referenced cairo in a project where freetype Library is also used. i was used freetype to load font into cairo, using below code

FT_Library lib;
FT_Face face;
FT_Init_FreeType(&lib);
FT_New_Face(lib, "D:\\Segoe.ttf", 0, &face);
cairo_font_face_t *cairo_ft_font_face_create_for_ft_face(FT_Face face, int load_flags);
cairo_font_face_t *myfont_face;
myfont_face = cairo_ft_font_face_create_for_ft_face(face,0);

before it was pointing error in the file cairo-ft.h (line 115)

error Cairo was not compiled with support for the freetype font backend

now , i'm getting compiler error,

LNK2019 unresolved external symbol "struct_cairo_font_face _cdecl cairo_ft_fony_face_create_for_ft(struct FT FaceRec ,int)" (?cairo_ft_fony_face_create_for_ft@@YAPAU_cario_font_face@@PAUFTFaceREcc@@H@Z) referenced in function "public:_thiscall cairoText::cairoText(Void)"(??0cairoText@@QAE@XZ)

below is the code for putting text on imageusing cairo

cv::Mat cairoText::putTextCairo(
    cv::Mat &targetImage,
    std::string const& text,
    cv::Point2d centerPoint,
    std::string const& fontFace,
    double fontSize,
    cv::Scalar textColor,
    bool fontItalic,
    bool fontBold)
{
    // Create Cairo
    cairo_surface_t* surface =
cairo_image_surface_create( CAIRO_FORMAT_ARGB32,
targetImage.cols,
targetImage.rows);

    cairo_t* cairo = cairo_create(surface);

    // Wrap Cairo with a OpenCV Mat
    cv::Mat cairoTarget(
        cairo_image_surface_get_height(surface),
        cairo_image_surface_get_width(surface),
        CV_8UC4,
        cairo_image_surface_get_data(surface),
        cairo_image_surface_get_stride(surface));

    // Put image onto Cairo
    cv::cvtColor(targetImage, cairoTarget, cv::COLOR_BGR2BGRA);

    // Set font and write text
    cairo_select_font_face(
        cairo,
        fontFace.c_str(),
        fontItalic ? CAIRO_FONT_SLANT_ITALIC : CAIRO_FONT_SLANT_NORMAL,
        fontBold ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL);

    cairo_set_font_size(cairo, fontSize);
    //cairo_set_source_rgb(cairo, textColor[2], textColor[1], textColor[0]);
    cairo_set_source_rgba(cairo, textColor[2], textColor[1], textColor[0], 25);
    cairo_text_extents_t extents;
    cairo_text_extents(cairo, text.c_str(), &extents);

    cairo_move_to(
        cairo,
        centerPoint.x - extents.width / 2 - extents.x_bearing,
        centerPoint.y - extents.height / 2 - extents.y_bearing);
    cairo_show_text(cairo, text.c_str());

    // Copy the data to the output image
    cv::cvtColor(cairoTarget, targetImage, cv::COLOR_BGRA2BGR);

    cairo_destroy(cairo);
    cairo_surface_destroy(surface);
    return targetImage;
}

how to build cairo with freetype library support? Thanks & Regards.

tordex commented 8 years ago

Yes, this build is compiled without freetype support. Look into cairo-ft.h, you have to define CAIRO_HAS_FT_FONT when compile cairo library.

Prakash19921206 commented 8 years ago

thanks for your reply. How to build Cairo with freetype support?