Merge branch 'master' into jgrpp

# Conflicts:
#	src/os/macosx/string_osx.cpp
This commit is contained in:
Jonathan G Rennison
2022-12-20 18:05:43 +00:00
15 changed files with 45 additions and 30 deletions

View File

@@ -587,10 +587,11 @@ static void DrawRailCatenaryRailway(const TileInfo *ti)
/* /*
* The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE. * The "wire"-sprite position is inside the tile, i.e. 0 <= sss->?_offset < TILE_SIZE.
* Therefore it is safe to use GetSlopePixelZ() for the elevation. * Therefore it is safe to use GetSlopePixelZ() for the elevation.
* Also note that the result of GetSlopePixelZ() is very special for bridge-ramps. * Also note that the result of GetSlopePixelZ() is very special for bridge-ramps, so we round the result up or
* down to the nearest full height change.
*/ */
AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset, AddSortableSpriteToDraw(wire_base + sss->image_offset, PAL_NONE, ti->x + sss->x_offset, ti->y + sss->y_offset,
sss->x_size, sss->y_size, sss->z_size, GetSlopePixelZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + sss->z_offset, sss->x_size, sss->y_size, sss->z_size, (GetSlopePixelZ(ti->x + sss->x_offset, ti->y + sss->y_offset) + 4) / 8 * 8 + sss->z_offset,
IsTransparencySet(TO_CATENARY)); IsTransparencySet(TO_CATENARY));
} }
} }

View File

@@ -33,12 +33,12 @@ protected:
int descender; ///< The descender value of the font. int descender; ///< The descender value of the font.
int units_per_em; ///< The units per EM value of the font. int units_per_em; ///< The units per EM value of the font.
static int GetDefaultFontHeight(FontSize fs);
public: public:
FontCache(FontSize fs); FontCache(FontSize fs);
virtual ~FontCache(); virtual ~FontCache();
static int GetDefaultFontHeight(FontSize fs);
/** /**
* Get the FontSize of the font. * Get the FontSize of the font.
* @return The FontSize. * @return The FontSize.

View File

@@ -65,14 +65,14 @@ 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(this->GetDefaultFontHeight(this->fs)); int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(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 != nullptr) { if (head != nullptr) {
/* 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(this->GetDefaultFontHeight(FS_SMALL)); int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
/* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
pixels = std::min(std::max(std::min<int>(head->Lowest_Rec_PPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); pixels = std::min(std::max(std::min<int>(head->Lowest_Rec_PPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);
} }

View File

@@ -28,8 +28,8 @@ static const int ASCII_LETTERSTART = 32; ///< First printable ASCII letter.
SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr) SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs), glyph_to_spriteid_map(nullptr)
{ {
this->InitializeUnicodeGlyphMap(); this->InitializeUnicodeGlyphMap();
this->height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleSpriteTrad(this->GetDefaultFontHeight(this->fs))) / 2; this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
} }
/** /**
@@ -106,8 +106,8 @@ void SpriteFontCache::ClearGlyphToSpriteMap()
void SpriteFontCache::ClearFontCache() void SpriteFontCache::ClearFontCache()
{ {
Layouter::ResetFontCache(this->fs); Layouter::ResetFontCache(this->fs);
this->height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); this->height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
this->ascender = (this->height - ScaleSpriteTrad(this->GetDefaultFontHeight(this->fs))) / 2; this->ascender = (this->height - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(this->fs))) / 2;
} }
const Sprite *SpriteFontCache::GetGlyph(GlyphID key) const Sprite *SpriteFontCache::GetGlyph(GlyphID key)

View File

@@ -11,6 +11,7 @@
#include "gfx_layout.h" #include "gfx_layout.h"
#include "string_func.h" #include "string_func.h"
#include "strings_func.h" #include "strings_func.h"
#include "zoom_func.h"
#include "debug.h" #include "debug.h"
#include "table/control_codes.h" #include "table/control_codes.h"
@@ -347,7 +348,7 @@ FallbackParagraphLayout::FallbackVisualRun::FallbackVisualRun(Font *font, const
if (isbuiltin) { if (isbuiltin) {
this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender. this->positions[2 * i + 1] = font->fc->GetAscender(); // Apply sprite font's ascender.
} else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) { } else if (chars[i] >= SCC_SPRITE_START && chars[i] <= SCC_SPRITE_END) {
this->positions[2 * i + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. this->positions[2 * i + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre
} else { } else {
this->positions[2 * i + 1] = 0; // No ascender adjustment. this->positions[2 * i + 1] = 0; // No ascender adjustment.
} }

View File

@@ -3370,7 +3370,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Represen
STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets
###length 2 ###length 2
STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Offset centred
STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite centred
STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Crosshair
STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative
STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets

View File

@@ -3371,7 +3371,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Represen
STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets. Ctrl+Click to move the sprite eight units at a time STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Move the sprite around, changing the X and Y offsets. Ctrl+Click to move the sprite eight units at a time
###length 2 ###length 2
STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Offset centered
STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite centered
STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Crosshair
STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Reset relative
STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Reset the current relative offsets

View File

@@ -3343,7 +3343,10 @@ STR_SPRITE_ALIGNER_SPRITE_TOOLTIP :{BLACK}Valitun
STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Liikuta spriteä ympäriinsä, muuttaen X- ja Y-sijainteja. Ctrl+napsautus siirtää spriteä kahdeksan yksikköä kerralla. STR_SPRITE_ALIGNER_MOVE_TOOLTIP :{BLACK}Liikuta spriteä ympäriinsä, muuttaen X- ja Y-sijainteja. Ctrl+napsautus siirtää spriteä kahdeksan yksikköä kerralla.
###length 2 ###length 2
STR_SPRITE_ALIGNER_CENTRE_OFFSET :{BLACK}Siirros keskitetty
STR_SPRITE_ALIGNER_CENTRE_SPRITE :{BLACK}Sprite keskitetty
STR_SPRITE_ALIGNER_CROSSHAIR :{BLACK}Hiusristikko
STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Nollaa suhteelliset STR_SPRITE_ALIGNER_RESET_BUTTON :{BLACK}Nollaa suhteelliset
STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Nollaa suhteelliset erotukset STR_SPRITE_ALIGNER_RESET_TOOLTIP :{BLACK}Nollaa suhteelliset erotukset

View File

@@ -173,7 +173,7 @@ void CoreTextFontCache::SetFontSize(int pixels)
{ {
if (pixels == 0) { if (pixels == 0) {
/* Try to determine a good height based on the height recommended by the font. */ /* Try to determine a good height based on the height recommended by the font. */
int scaled_height = ScaleGUITrad(this->GetDefaultFontHeight(this->fs)); int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
pixels = scaled_height; pixels = scaled_height;
CFAutoRelease<CTFontRef> font(CTFontCreateWithFontDescriptor(this->font_desc.get(), 0.0f, nullptr)); CFAutoRelease<CTFontRef> font(CTFontCreateWithFontDescriptor(this->font_desc.get(), 0.0f, nullptr));
@@ -197,7 +197,7 @@ void CoreTextFontCache::SetFontSize(int pixels)
/* 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(this->GetDefaultFontHeight(FS_SMALL)); int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
/* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
pixels = std::min(std::max(std::min<int>(min_size, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); pixels = std::min(std::max(std::min<int>(min_size, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);
} }

View File

@@ -13,6 +13,7 @@
#include "../../strings_func.h" #include "../../strings_func.h"
#include "../../table/control_codes.h" #include "../../table/control_codes.h"
#include "../../fontcache.h" #include "../../fontcache.h"
#include "../../zoom_func.h"
#include "../../scope.h" #include "../../scope.h"
#include "macos.h" #include "macos.h"
@@ -246,7 +247,7 @@ CoreTextParagraphLayout::CoreTextVisualRun::CoreTextVisualRun(CTRunRef run, Font
if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END) { if (buff[this->glyph_to_char[i]] >= SCC_SPRITE_START && buff[this->glyph_to_char[i]] <= SCC_SPRITE_END) {
this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]); this->glyphs[i] = font->fc->MapCharToGlyph(buff[this->glyph_to_char[i]]);
this->positions[i * 2 + 0] = pts[i].x; this->positions[i * 2 + 0] = pts[i].x;
this->positions[i * 2 + 1] = font->fc->GetAscender() - font->fc->GetGlyph(this->glyphs[i])->height - 1; // Align sprite glyphs to font baseline. this->positions[i * 2 + 1] = (font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(font->fc->GetSize()))) / 2; // Align sprite font to centre
} else { } else {
this->glyphs[i] = gl[i]; this->glyphs[i] = gl[i];
this->positions[i * 2 + 0] = pts[i].x; this->positions[i * 2 + 0] = pts[i].x;

View File

@@ -392,7 +392,7 @@ void Win32FontCache::SetFontSize(FontSize fs, 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(this->GetDefaultFontHeight(this->fs)); int scaled_height = ScaleGUITrad(FontCache::GetDefaultFontHeight(this->fs));
pixels = scaled_height; pixels = scaled_height;
HFONT temp = CreateFontIndirect(&this->logfont); HFONT temp = CreateFontIndirect(&this->logfont);
@@ -405,7 +405,7 @@ void Win32FontCache::SetFontSize(FontSize fs, int pixels)
/* 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(this->GetDefaultFontHeight(FS_SMALL)); int diff = scaled_height - ScaleGUITrad(FontCache::GetDefaultFontHeight(FS_SMALL));
/* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */ /* Clamp() is not used as scaled_height could be greater than MAX_FONT_SIZE, which is not permitted in Clamp(). */
pixels = std::min(std::max(std::min<int>(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE); pixels = std::min(std::max(std::min<int>(otm->otmusMinimumPPEM, MAX_FONT_MIN_REC_SIZE) + diff, scaled_height), MAX_FONT_SIZE);

View File

@@ -14,6 +14,7 @@
#include "../../strings_func.h" #include "../../strings_func.h"
#include "../../string_func.h" #include "../../string_func.h"
#include "../../table/control_codes.h" #include "../../table/control_codes.h"
#include "../../zoom_func.h"
#include "win32.h" #include "win32.h"
#include <vector> #include <vector>
@@ -195,7 +196,7 @@ static bool UniscribeShapeRun(const UniscribeParagraphLayoutFactory::CharType *b
if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) { if (buff[range.pos + i] >= SCC_SPRITE_START && buff[range.pos + i] <= SCC_SPRITE_END) {
auto pos = range.char_to_glyph[i]; auto pos = range.char_to_glyph[i];
range.ft_glyphs[pos] = range.font->fc->MapCharToGlyph(buff[range.pos + i]); range.ft_glyphs[pos] = range.font->fc->MapCharToGlyph(buff[range.pos + i]);
range.offsets[pos].dv = range.font->fc->GetAscender() - range.font->fc->GetGlyph(range.ft_glyphs[pos])->height - 1; // Align sprite glyphs to font baseline. range.offsets[pos].dv = (range.font->fc->GetHeight() - ScaleSpriteTrad(FontCache::GetDefaultFontHeight(range.font->fc->GetSize()))) / 2; // Align sprite font to centre
range.advances[pos] = range.font->fc->GetGlyphWidth(range.ft_glyphs[pos]); range.advances[pos] = range.font->fc->GetGlyphWidth(range.ft_glyphs[pos]);
} }
} }

View File

@@ -327,7 +327,9 @@ struct SortableSpriteStruct {
/** Distance between wire and rail */ /** Distance between wire and rail */
static const uint ELRAIL_ELEVATION = 10; static const uint ELRAIL_ELEVATION = 10;
/** Wires that a draw one level higher than the north corner. */ /** Wires that a draw one level higher than the north corner. */
static const uint ELRAIL_ELEVRAISE = ELRAIL_ELEVATION + TILE_HEIGHT; static const uint ELRAIL_ELEVRAISE = ELRAIL_ELEVATION + TILE_HEIGHT + 1;
/** Wires that a draw one level lower than the north corner. */
static const uint ELRAIL_ELEVLOWER = ELRAIL_ELEVATION - 1;
static const SortableSpriteStruct RailCatenarySpriteData[] = { static const SortableSpriteStruct RailCatenarySpriteData[] = {
/* X direction /* X direction
@@ -345,9 +347,9 @@ static const SortableSpriteStruct RailCatenarySpriteData[] = {
/* "down" tiles /* "down" tiles
* Wires */ * Wires */
{ WSO_X_SW_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 6: Wire in X pitch down, pylon on the SW end { WSO_X_SW_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 6: Wire in X pitch down, pylon on the SW end
{ WSO_X_NE_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 7: Wire in X pitch down, pylon on the NE end { WSO_X_NE_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 7: Wire in X pitch down, pylon on the NE end
{ WSO_X_SHORT_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVATION }, //! 8: Wire in X pitch down, pylon on both ends { WSO_X_SHORT_DOWN, 0, 7, 15, 8, 1, ELRAIL_ELEVLOWER }, //! 8: Wire in X pitch down, pylon on both ends
/* Y direction /* Y direction
@@ -365,9 +367,9 @@ static const SortableSpriteStruct RailCatenarySpriteData[] = {
/* "down" tiles /* "down" tiles
* Wires */ * Wires */
{ WSO_Y_SE_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!15: Wire in Y pitch down, pylon on the SE end { WSO_Y_SE_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!15: Wire in Y pitch down, pylon on the SE end
{ WSO_Y_NW_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!16: Wire in Y pitch down, pylon on the NW end { WSO_Y_NW_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!16: Wire in Y pitch down, pylon on the NW end
{ WSO_Y_SHORT_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVATION }, //!17: Wire in Y pitch down, pylon on both ends { WSO_Y_SHORT_DOWN, 7, 0, 8, 15, 1, ELRAIL_ELEVLOWER }, //!17: Wire in Y pitch down, pylon on both ends
/* NS Direction */ /* NS Direction */
{ WSO_NS_SHORT, 8, 0, 8, 8, 1, ELRAIL_ELEVATION }, //!18: LEFT trackbit wire, pylon on both ends { WSO_NS_SHORT, 8, 0, 8, 8, 1, ELRAIL_ELEVATION }, //!18: LEFT trackbit wire, pylon on both ends

View File

@@ -3176,10 +3176,10 @@ struct VehicleDetailsWindow : Window {
/* Articulated road vehicles use a complete line. */ /* Articulated road vehicles use a complete line. */
if (v->type == VEH_ROAD && v->HasArticulatedPart()) { if (v->type == VEH_ROAD && v->HasArticulatedPart()) {
DrawVehicleImage(v, tr, INVALID_VEHICLE, EIT_IN_DETAILS, 0); DrawVehicleImage(v, tr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0);
} else { } else {
Rect sr = tr.WithWidth(sprite_width, rtl); Rect sr = tr.WithWidth(sprite_width, rtl);
DrawVehicleImage(v, sr, INVALID_VEHICLE, EIT_IN_DETAILS, 0); DrawVehicleImage(v, sr.WithHeight(ScaleGUITrad(GetVehicleHeight(v->type)), false), INVALID_VEHICLE, EIT_IN_DETAILS, 0);
} }
DrawVehicleDetails(v, tr.Indent(sprite_width, rtl), 0, 0, this->tab); DrawVehicleDetails(v, tr.Indent(sprite_width, rtl), 0, 0, this->tab);

View File

@@ -413,12 +413,12 @@ void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button
bool above = false; bool above = false;
/* Available height below (or above, if the dropdown is placed above the widget). */ /* Available height below (or above, if the dropdown is placed above the widget). */
uint available_height = std::max(GetMainViewBottom() - top - WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0U); uint available_height = std::max(GetMainViewBottom() - top - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
/* If the dropdown doesn't fully fit below the widget... */ /* If the dropdown doesn't fully fit below the widget... */
if (height > available_height) { if (height > available_height) {
uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0U); uint available_height_above = std::max(w->top + wi_rect.top - GetMainViewTop() - (int)WidgetDimensions::scaled.fullbevel.Vertical() * 2, 0);
/* Put the dropdown above if there is more available space. */ /* Put the dropdown above if there is more available space. */
if (available_height_above > available_height) { if (available_height_above > available_height) {