void
PonscripterLabel::drawGlyph(SDL_Surface* dst_surface, Fontinfo* info,
        SDL_Color &color, unsigned short unicode, float x, int y,
    bool shadow_flag, AnimationInfo* cache_info, SDL_Rect* clip,
    SDL_Rect &dst_rect)
{
    float minx, maxy;

    int sz = info->doSize();

    info->font()->get_metrics(unicode, &minx, NULL, NULL, &maxy);

    Glyph g = renderGlyph(info->font(), unicode, sz,
              x + minx - floor(x + minx));
    bool rotate_flag = false;

    if (g.bitmap) {
    minx = g.left;
    maxy = g.top;
    }
    
    dst_rect.x = int(floor(x + minx));
    dst_rect.y = y + info->font()->ascent() - int(ceil(maxy));

    if (shadow_flag) {
        if (info->getRTL())
            dst_rect.x -= shade_distance[0];
        else
            dst_rect.x += shade_distance[0];
        dst_rect.y += shade_distance[1];
    }

    if (g.bitmap) {
        dst_rect.w = g.bitmap->w;
        dst_rect.h = g.bitmap->h;

        if (cache_info == &text_info) {
            // When rendering text
            cache_info->blendText(g.bitmap, dst_rect.x, dst_rect.y,
                                  color, clip);
            cache_info->blendOnSurface(dst_surface, 0, 0, dst_rect);
        }
        else {
            if (cache_info)
                cache_info->blendText(g.bitmap, dst_rect.x, dst_rect.y,
                                      color, clip);

            if (dst_surface)
                alphaBlendText(dst_surface, dst_rect, g.bitmap, color, clip,
                               rotate_flag);
        }
    }
}
Example #2
0
void ONScripter::drawGlyph( SDL_Surface *dst_surface, FontInfo *info, SDL_Color &color, char* text, int xy[2], bool shadow_flag, AnimationInfo *cache_info, SDL_Rect *clip, SDL_Rect &dst_rect )
{
    unsigned short unicode;
    if (IS_TWO_BYTE(text[0])){
        unsigned index = ((unsigned char*)text)[0];
        index = index << 8 | ((unsigned char*)text)[1];
        unicode = convSJIS2UTF16( index );
    }
    else{
        if ((text[0] & 0xe0) == 0xa0 || (text[0] & 0xe0) == 0xc0) unicode = ((unsigned char*)text)[0] - 0xa0 + 0xff60;
        else unicode = text[0];
    }

    int minx, maxx, miny, maxy, advanced;
#if 0
    if (TTF_GetFontStyle( (TTF_Font*)info->ttf_font ) !=
        (info->is_bold?TTF_STYLE_BOLD:TTF_STYLE_NORMAL) )
        TTF_SetFontStyle( (TTF_Font*)info->ttf_font, (info->is_bold?TTF_STYLE_BOLD:TTF_STYLE_NORMAL));
#endif    
    TTF_GlyphMetrics( (TTF_Font*)info->ttf_font, unicode,
                      &minx, &maxx, &miny, &maxy, &advanced );
    //printf("min %d %d %d %d %d %d\n", minx, maxx, miny, maxy, advanced,TTF_FontAscent((TTF_Font*)info->ttf_font)  );
    
    SDL_Surface *tmp_surface = renderGlyph( (TTF_Font*)info->ttf_font, unicode );

    bool rotate_flag = false;
    if ( info->getTateyokoMode() == FontInfo::TATE_MODE && IS_ROTATION_REQUIRED(text) ) rotate_flag = true;
    
    dst_rect.x = xy[0] + minx;
    dst_rect.y = xy[1] + TTF_FontAscent((TTF_Font*)info->ttf_font) - maxy;
    dst_rect.y -= (TTF_FontHeight((TTF_Font*)info->ttf_font) - info->font_size_xy[1]*screen_ratio1/screen_ratio2)/2;

    if ( rotate_flag ) dst_rect.x += miny - minx;
        
    if ( info->getTateyokoMode() == FontInfo::TATE_MODE && IS_TRANSLATION_REQUIRED(text) ){
        dst_rect.x += info->font_size_xy[0]/2;
        dst_rect.y -= info->font_size_xy[0]/2;
    }

    if ( shadow_flag ){
        dst_rect.x += shade_distance[0];
        dst_rect.y += shade_distance[1];
    }

    if ( tmp_surface ){
        if (rotate_flag){
            dst_rect.w = tmp_surface->h;
            dst_rect.h = tmp_surface->w;
        }
        else{
            dst_rect.w = tmp_surface->w;
            dst_rect.h = tmp_surface->h;
        }

        if (cache_info)
            cache_info->blendText( tmp_surface, dst_rect.x, dst_rect.y, color, clip, rotate_flag );
        
        if (dst_surface)
            alphaBlendText( dst_surface, dst_rect, tmp_surface, color, clip, rotate_flag );
    }
}