Files
fs2open.github.com/code/graphics/software/NVGFont.h
T
Goober5000andClaude Opus 4.8 f3817c80fa Scale font line and tab advance by the font scale factor
Multi-line and tabbed strings drawn with a scaleMultiplier != 1 overlapped
or misaligned because the font code advanced newlines and tabs by the
unscaled font height/tab width -- most visible in FRED's viewport labels
now that they honor an adjustable font scale.

Scale the newline and tab advance in both the rendering and measurement
paths of each backend: the NVG path (gr_string and NVGFont::getStringSize)
and the VFNT path (gr_string_old and VFNTFont::getStringSize), which also
gains tab handling.  The tab width is hoisted onto the shared FSFont base
so both backends share it.

While here, pass the FSFont wrapper to gr_string_old instead of a bag of
scalars, make its font pointer const, and consolidate the
get_char_width_old externs into a single declaration in font_internal.h.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
2026-09-03 01:55:03 -04:00

46 lines
1.1 KiB
C++

#pragma once
#include "globalincs/pstypes.h"
#include "graphics/software/FSFont.h"
namespace font
{
struct font;
class NVGFont : public FSFont
{
private:
int m_handle = -1;
float m_letterSpacing = 0.0f;
float m_size = 12.0f;
font* m_specialCharacters = nullptr;
float m_lineHeight = 0.0f;
public:
NVGFont() = default;
~NVGFont() override = default;
int getHandle() const { return m_handle; }
float getSize() const { return m_size; }
float getLetterSpacing() const { return m_letterSpacing; }
font* getSpecialCharacterFont() const { return m_specialCharacters; }
void setHandle(int handle);
void setSize(float size);
void setLetterSpacing(float spacing);
void setSpecialCharacterFont(font* fontData);
FontType getType() const override { return NVG_FONT; };
float getTextHeight() const override;
void getStringSize(const char *text, size_t textLen, int resize_mode,
float *width, float *height, float scaleMultiplier = 1.0f) const override;
void computeFontMetrics() override;
static size_t getTokenLength(const char *string, size_t maxLength);
};
}