Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 尝试将FreeType与CImg一起使用_C++_Freetype - Fatal编程技术网

C++ 尝试将FreeType与CImg一起使用

C++ 尝试将FreeType与CImg一起使用,c++,freetype,C++,Freetype,我使用一些使用FreeType2的代码: void drawText( FT_Face &face, cimg_library::CImg < unsigned char > &image, const int &heightText, const std::wstring &text, const int &leftTopX, const int &leftTopY, int &width, int &height,

我使用一些使用FreeType2的代码:

void drawText( FT_Face &face, cimg_library::CImg < unsigned char > &image, const int &heightText, const std::wstring &text, const int &leftTopX, const int &leftTopY, int &width, int &height, unsigned char fontColor[] = NULL, const int separeteGlyphWidth = 1 ) {

    width = 0;
    height = 0;

    FT_Set_Pixel_Sizes( face, 0, heightText );
    FT_GlyphSlot glyphSlot = face->glyph;  

    int shiftX = leftTopX;
    int shiftY = 0;
    for( int numberSymbol = 0; numberSymbol < text.length(); ++numberSymbol ){

        shiftY = leftTopY;

        bool isSpace = false;
        FT_ULong symbol = text[ numberSymbol ]; //FT_ULong symbol = text.at(numberSymbol);
        if (symbol == ' ') {
            symbol = 'a';
            isSpace = true;
        }

        if( FT_Load_Char( face, symbol, FT_LOAD_RENDER ) ) throw "Error, glyph not load!! \n";

        shiftY = heightText - glyphSlot->bitmap.rows;
        if ( shiftY < 0 ) shiftY = 0;

        std::cout << "char: " << (char) text.at( numberSymbol ) << " \tshiftY = " << shiftY << "\t rows = " << glyphSlot->bitmap.rows << "\t extra = " << ( glyphSlot->advance.y >> 6 ) << "\n";

        if ( !isSpace ) drawGlyph( glyphSlot, image, shiftX, shiftY, fontColor );

        shiftX += glyphSlot->bitmap.width + separeteGlyphWidth;

        if( height < shiftY + glyphSlot->bitmap.rows ) height = shiftY + glyphSlot->bitmap.rows;
        width = shiftX;

    }

}


std::string str = "Let me speak from my heart!";
std::wstring wStr( str.begin(), str.end() );

int width, height;
drawText( face, myCImg, 50, wStr, 50, 50, width, height );
void drawText(FT_Face&Face,cimg_library::cimg&image,const int&heightText,const std::wstring&text,const int&leftTopX,const int&leftTopY,int&width,int&height,unsigned char fontColor[]=NULL,const int separateglyphwidth=1){
宽度=0;
高度=0;
设置像素大小(面、0、高度文本);
FT_GlyphSlot GlyphSlot=面->字形;
int shiftX=leftTopX;
int-shiftY=0;
for(int numberSymbol=0;numberSymbolbitmap.rows;
如果(移位<0)移位=0;

std::cout metrics.vertAdvance但我不知道如何正确使用它。

快速查看Y偏移的值似乎应该基于
位图\u top
,如果需要像素坐标

所以我建议换一条线

shiftY = heightText - glyphSlot->bitmap.rows;

通过查看以以下方式使用这些值的,似乎也证实了这一点:

/* now, draw to our target surface */
my_draw_bitmap( &slot->bitmap,
              pen_x + slot->bitmap_left,
              pen_y - slot->bitmap_top );

/* increment pen position */
pen_x += slot->advance.x >> 6;

只要浏览一下文档,我就会尝试使用
bitmap\u-top
shiftY=heightText-glyphSlot->bitmap\u-top;
@PeterT,哈,谢谢你!它真的很有效!:)你可以添加这些信息作为答案-我会接受的。再次感谢你!这真的帮了我的忙!
/* now, draw to our target surface */
my_draw_bitmap( &slot->bitmap,
              pen_x + slot->bitmap_left,
              pen_y - slot->bitmap_top );

/* increment pen position */
pen_x += slot->advance.x >> 6;