mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
This commit is contained in:
parent
13962a8475
commit
eeae4512ae
@ -184,12 +184,12 @@ uint SpriteFontCache::GetGlyphWidth(GlyphID key)
|
|||||||
{
|
{
|
||||||
SpriteID sprite = this->GetUnicodeGlyph(key);
|
SpriteID sprite = this->GetUnicodeGlyph(key);
|
||||||
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
|
||||||
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleGUITrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
return SpriteExists(sprite) ? GetSprite(sprite, ST_FONT)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SpriteFontCache::GetHeight() const
|
int SpriteFontCache::GetHeight() const
|
||||||
{
|
{
|
||||||
return this->height * (1 << (ZOOM_LVL_OUT_4X - _font_zoom));
|
return ScaleFontTrad(this->height);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SpriteFontCache::GetDrawGlyphShadow()
|
bool SpriteFontCache::GetDrawGlyphShadow()
|
||||||
@ -282,21 +282,19 @@ void FreeTypeFontCache::SetFontSize(FontSize fs, FT_Face face, int pixels)
|
|||||||
{
|
{
|
||||||
if (pixels == 0) {
|
if (pixels == 0) {
|
||||||
/* Try to determine a good height based on the minimal height recommended by the font. */
|
/* Try to determine a good height based on the minimal height recommended by the font. */
|
||||||
int scaled_height = ScaleGUITrad(_default_font_height[this->fs]);
|
int scaled_height = ScaleFontTrad(_default_font_height[this->fs]);
|
||||||
pixels = scaled_height;
|
pixels = scaled_height;
|
||||||
|
|
||||||
TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->face, ft_sfnt_head);
|
TT_Header *head = (TT_Header *)FT_Get_Sfnt_Table(this->face, ft_sfnt_head);
|
||||||
if (head != NULL) {
|
if (head != NULL) {
|
||||||
/* Font height is minimum height plus the difference between the default
|
/* Font height is minimum height plus the difference between the default
|
||||||
* height for this font size and the small size. */
|
* height for this font size and the small size. */
|
||||||
int diff = scaled_height - ScaleGUITrad(_default_font_height[FS_SMALL]);
|
int diff = scaled_height - ScaleFontTrad(_default_font_height[FS_SMALL]);
|
||||||
pixels = Clamp(min(head->Lowest_Rec_PPEM, 20) + diff, scaled_height, MAX_FONT_SIZE);
|
pixels = Clamp(min(head->Lowest_Rec_PPEM, 20) + diff, scaled_height, MAX_FONT_SIZE);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
pixels = ScaleFontTrad(pixels);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Apply user-specified font zoom. */
|
|
||||||
pixels *= (1 << (ZOOM_LVL_OUT_4X - _font_zoom));
|
|
||||||
|
|
||||||
this->used_size = pixels;
|
this->used_size = pixels;
|
||||||
|
|
||||||
FT_Error err = FT_Set_Pixel_Sizes(this->face, 0, pixels);
|
FT_Error err = FT_Set_Pixel_Sizes(this->face, 0, pixels);
|
||||||
|
@ -84,4 +84,24 @@ static inline int ScaleGUITrad(int value)
|
|||||||
return UnScaleGUI(value * ZOOM_LVL_BASE);
|
return UnScaleGUI(value * ZOOM_LVL_BASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Short-hand to apply font zoom level.
|
||||||
|
* @param value Pixel amount at #ZOOM_LVL_BEGIN (full zoom in).
|
||||||
|
* @return Pixel amount at #ZOOM_LVL_FONT (current interface size).
|
||||||
|
*/
|
||||||
|
static inline int UnScaleFont(int value)
|
||||||
|
{
|
||||||
|
return UnScaleByZoom(value, ZOOM_LVL_FONT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale traditional pixel dimensions to Font zoom level.
|
||||||
|
* @param value Pixel amount at #ZOOM_LVL_BASE (traditional "normal" interface size).
|
||||||
|
* @return Pixel amount at #ZOOM_LVL_FONT (current interface size).
|
||||||
|
*/
|
||||||
|
static inline int ScaleFontTrad(int value)
|
||||||
|
{
|
||||||
|
return UnScaleFont(value * ZOOM_LVL_BASE);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* ZOOM_FUNC_H */
|
#endif /* ZOOM_FUNC_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user