Move font API to GpCommon

This commit is contained in:
elasota
2020-09-12 14:01:51 -04:00
parent f07137b52d
commit 987a1dea75
43 changed files with 189 additions and 190 deletions

View File

@@ -1,8 +1,9 @@
#include "FontFamily.h"
#include "GpIOStream.h"
#include "HostFileSystem.h"
#include "IGpFontHandler.h"
#include "HostFontHandler.h"
#include "HostFont.h"
#include "IGpFont.h"
#include <stdlib.h>
#include <new>
@@ -15,9 +16,9 @@ namespace PortabilityLayer
if (!sysFontStream)
return;
PortabilityLayer::HostFontHandler *fontHandler = PortabilityLayer::HostFontHandler::GetInstance();
IGpFontHandler *fontHandler = PortabilityLayer::HostFontHandler::GetInstance();
PortabilityLayer::HostFont *font = fontHandler->LoadFont(sysFontStream);
IGpFont *font = fontHandler->LoadFont(sysFontStream);
if (!fontHandler->KeepStreamOpen())
sysFontStream->Close();
@@ -49,7 +50,7 @@ namespace PortabilityLayer
return m_defaultVariation;
}
PortabilityLayer::HostFont *FontFamily::GetFontForVariation(int variation) const
IGpFont *FontFamily::GetFontForVariation(int variation) const
{
return m_fonts[variation];
}
@@ -88,7 +89,7 @@ namespace PortabilityLayer
{
for (unsigned int i = 0; i < kNumVariations; i++)
{
if (PortabilityLayer::HostFont *font = m_fonts[i])
if (IGpFont *font = m_fonts[i])
font->Destroy();
}
}

View File

@@ -4,11 +4,10 @@
#include <stdint.h>
class PLPasStr;
struct IGpFont;
namespace PortabilityLayer
{
class HostFont;
enum FontFamilyFlags
{
FontFamilyFlag_None = 0,
@@ -27,15 +26,15 @@ namespace PortabilityLayer
void SetDefaultVariation(int defaultVariation);
int GetVariationForFlags(int variation) const;
PortabilityLayer::HostFont *GetFontForVariation(int variation) const;
PortabilityLayer::FontHacks GetHacksForVariation(int variation) const;
IGpFont *GetFontForVariation(int variation) const;
FontHacks GetHacksForVariation(int variation) const;
static FontFamily *Create();
void Destroy();
private:
PortabilityLayer::FontHacks m_hacks[kNumVariations];
PortabilityLayer::HostFont *m_fonts[kNumVariations];
FontHacks m_hacks[kNumVariations];
IGpFont *m_fonts[kNumVariations];
uint8_t m_defaultVariation;
FontFamily();

View File

@@ -3,7 +3,7 @@
#include "FontRenderer.h"
#include "HostFileSystem.h"
#include "HostFont.h"
#include "IGpFont.h"
#include "HostFontHandler.h"
#include "GpIOStream.h"
#include "RenderedFont.h"
@@ -24,7 +24,7 @@ namespace PortabilityLayer
FontFamily *GetSystemFont(int textSize, int variationFlags) const override;
FontFamily *GetApplicationFont(int textSize, int variationFlags) const override;
RenderedFont *GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks) override;
RenderedFont *GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) override;
RenderedFont *GetRenderedFontFromFamily(FontFamily *font, int size, bool aa, int flags) override;
static FontManagerImpl *GetInstance();
@@ -35,7 +35,7 @@ namespace PortabilityLayer
struct CachedRenderedFont
{
RenderedFont *m_rfont;
const HostFont *m_font;
const IGpFont *m_font;
int m_size;
uint32_t m_lastUsage;
bool m_aa;
@@ -80,7 +80,7 @@ namespace PortabilityLayer
if (m_applicationFont)
m_applicationFont->Destroy();
HostFontHandler *hfh = HostFontHandler::GetInstance();
IGpFontHandler *hfh = HostFontHandler::GetInstance();
if (m_systemFont)
{
@@ -110,7 +110,7 @@ namespace PortabilityLayer
return m_applicationFont;
}
RenderedFont *FontManagerImpl::GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks)
RenderedFont *FontManagerImpl::GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks)
{
CachedRenderedFont *newCacheSlot = &m_cachedRenderedFonts[0];
@@ -164,7 +164,7 @@ namespace PortabilityLayer
{
const int variation = fontFamily->GetVariationForFlags(flags);
PortabilityLayer::HostFont *hostFont = fontFamily->GetFontForVariation(variation);
IGpFont *hostFont = fontFamily->GetFontForVariation(variation);
if (!hostFont)
return nullptr;

View File

@@ -2,10 +2,11 @@
#include "FontHacks.h"
struct IGpFont;
namespace PortabilityLayer
{
class FontFamily;
class HostFont;
class RenderedFont;
class FontManager
@@ -17,7 +18,7 @@ namespace PortabilityLayer
virtual FontFamily *GetSystemFont(int fontSize, int variationFlags) const = 0;
virtual FontFamily *GetApplicationFont(int fontSize, int variationFlags) const = 0;
virtual RenderedFont *GetRenderedFont(HostFont *font, int size, bool aa, FontHacks fontHacks) = 0;
virtual RenderedFont *GetRenderedFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) = 0;
virtual RenderedFont *GetRenderedFontFromFamily(FontFamily *fontFamily, int fontSize, bool aa, int flags) = 0;
static FontManager *GetInstance();

View File

@@ -1,14 +1,14 @@
#include "FontRenderer.h"
#include "CoreDefs.h"
#include "HostFont.h"
#include "IGpFont.h"
#include "HostFontHandler.h"
#include "HostFontRenderedGlyph.h"
#include "IGpFontRenderedGlyph.h"
#include "MacRomanConversion.h"
#include "PLPasStr.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "RenderedGlyphMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "GpRenderedGlyphMetrics.h"
#include <assert.h>
#include <string.h>
@@ -20,15 +20,15 @@ namespace PortabilityLayer
class RenderedFontImpl final : public RenderedFont
{
public:
bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const override;
const RenderedFontMetrics &GetMetrics() const override;
bool GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const override;
const GpRenderedFontMetrics &GetMetrics() const override;
size_t MeasureString(const uint8_t *chars, size_t len) const override;
bool IsAntiAliased() const override;
void Destroy() override;
void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics);
void SetFontMetrics(const RenderedFontMetrics &metrics);
void SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics);
void SetFontMetrics(const GpRenderedFontMetrics &metrics);
static RenderedFontImpl *Create(size_t glyphDataSize, bool aa);
@@ -37,9 +37,9 @@ namespace PortabilityLayer
~RenderedFontImpl();
size_t m_dataOffsets[256];
RenderedGlyphMetrics m_glyphMetrics[256];
GpRenderedGlyphMetrics m_glyphMetrics[256];
RenderedFontMetrics m_fontMetrics;
GpRenderedFontMetrics m_fontMetrics;
bool m_isAntiAliased;
void *m_data;
@@ -48,7 +48,7 @@ namespace PortabilityLayer
class FontRendererImpl final : public FontRenderer
{
public:
RenderedFont *RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks) override;
RenderedFont *RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) override;
static FontRendererImpl *GetInstance();
@@ -56,7 +56,7 @@ namespace PortabilityLayer
static FontRendererImpl ms_instance;
};
bool RenderedFontImpl::GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const
bool RenderedFontImpl::GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const
{
const size_t dataOffset = m_dataOffsets[character];
if (!dataOffset)
@@ -68,7 +68,7 @@ namespace PortabilityLayer
return true;
}
const RenderedFontMetrics &RenderedFontImpl::GetMetrics() const
const GpRenderedFontMetrics &RenderedFontImpl::GetMetrics() const
{
return m_fontMetrics;
}
@@ -79,7 +79,7 @@ namespace PortabilityLayer
for (size_t i = 0; i < len; i++)
{
const RenderedGlyphMetrics &metrics = m_glyphMetrics[chars[i]];
const GpRenderedGlyphMetrics &metrics = m_glyphMetrics[chars[i]];
measure += metrics.m_advanceX;
}
@@ -97,14 +97,14 @@ namespace PortabilityLayer
free(this);
}
void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const RenderedGlyphMetrics &metrics)
void RenderedFontImpl::SetCharData(unsigned int charID, const void *data, size_t dataOffset, const GpRenderedGlyphMetrics &metrics)
{
m_dataOffsets[charID] = dataOffset;
m_glyphMetrics[charID] = metrics;
memcpy(static_cast<uint8_t*>(m_data) + dataOffset, data, metrics.m_glyphDataPitch * metrics.m_glyphHeight);
}
void RenderedFontImpl::SetFontMetrics(const RenderedFontMetrics &metrics)
void RenderedFontImpl::SetFontMetrics(const GpRenderedFontMetrics &metrics)
{
m_fontMetrics = metrics;
}
@@ -141,7 +141,7 @@ namespace PortabilityLayer
{
}
RenderedFont *FontRendererImpl::RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks)
RenderedFont *FontRendererImpl::RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks)
{
const unsigned int numCharacters = 256;
@@ -152,7 +152,7 @@ namespace PortabilityLayer
if (!font->GetLineSpacing(size, lineSpacing))
return nullptr;
HostFontRenderedGlyph *glyphs[numCharacters];
IGpFontRenderedGlyph *glyphs[numCharacters];
for (unsigned int i = 0; i < numCharacters; i++)
glyphs[i] = nullptr;
@@ -172,7 +172,7 @@ namespace PortabilityLayer
{
if (glyphs[i])
{
const RenderedGlyphMetrics &metrics = glyphs[i]->GetMetrics();
const GpRenderedGlyphMetrics &metrics = glyphs[i]->GetMetrics();
glyphDataSize += metrics.m_glyphDataPitch * metrics.m_glyphHeight;
}
}
@@ -187,9 +187,9 @@ namespace PortabilityLayer
{
if (glyphs[i])
{
HostFontRenderedGlyph *glyph = glyphs[i];
IGpFontRenderedGlyph *glyph = glyphs[i];
RenderedGlyphMetrics metrics = glyph->GetMetrics();
GpRenderedGlyphMetrics metrics = glyph->GetMetrics();
const void *data = glyph->GetData();
if (fontHacks == FontHacks_Roboto && !aa)
@@ -219,7 +219,7 @@ namespace PortabilityLayer
}
// Compute metrics
RenderedFontMetrics fontMetrics;
GpRenderedFontMetrics fontMetrics;
fontMetrics.m_linegap = lineSpacing;
fontMetrics.m_ascent = 0;
fontMetrics.m_descent = 0;
@@ -227,7 +227,7 @@ namespace PortabilityLayer
bool measuredAnyGlyphs = false;
for (char capChar = 'A'; capChar <= 'Z'; capChar++)
{
const RenderedGlyphMetrics *glyphMetrics;
const GpRenderedGlyphMetrics *glyphMetrics;
const void *glyphData;
if (rfont->GetGlyph(static_cast<unsigned int>(capChar), glyphMetrics, glyphData) && glyphMetrics != nullptr)
{

View File

@@ -2,15 +2,16 @@
#include "FontHacks.h"
struct IGpFont;
namespace PortabilityLayer
{
class RenderedFont;
class HostFont;
class FontRenderer
{
public:
virtual RenderedFont *RenderFont(HostFont *font, int size, bool aa, FontHacks fontHacks) = 0;
virtual RenderedFont *RenderFont(IGpFont *font, int size, bool aa, FontHacks fontHacks) = 0;
static FontRenderer *GetInstance();
};

View File

@@ -22,13 +22,13 @@
struct IGpAudioDriver;
struct IGpLogDriver;
struct IGpInputDriver;
struct IGpFontHandler;
namespace PortabilityLayer
{
class HostFileSystem;
class HostDisplayDriver;
class HostSystemServices;
class HostFontHandler;
class HostVOSEventQueue;
}
@@ -46,7 +46,7 @@ public:
virtual void PL_HostLogDriver_SetInstance(IGpLogDriver *instance) = 0;
virtual void PL_HostInputDriver_SetInstances(IGpInputDriver *const* instances, size_t numInstances) = 0;
virtual void PL_HostSystemServices_SetInstance(PortabilityLayer::HostSystemServices *instance) = 0;
virtual void PL_HostFontHandler_SetInstance(PortabilityLayer::HostFontHandler *instance) = 0;
virtual void PL_HostFontHandler_SetInstance(IGpFontHandler *instance) = 0;
virtual void PL_HostVOSEventQueue_SetInstance(PortabilityLayer::HostVOSEventQueue *instance) = 0;
virtual void PL_InstallHostSuspendHook(PortabilityLayer::HostSuspendHook_t hook, void *context) = 0;

View File

@@ -1,17 +0,0 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
class HostFontRenderedGlyph;
struct RenderedFontMetrics;
class HostFont
{
public:
virtual void Destroy() = 0;
virtual HostFontRenderedGlyph *Render(uint32_t unicodeCodePoint, unsigned int size, bool aa) = 0;
virtual bool GetLineSpacing(unsigned int size, int32_t &outSpacing) = 0;
};
}

View File

@@ -2,15 +2,15 @@
namespace PortabilityLayer
{
void HostFontHandler::SetInstance(HostFontHandler *instance)
void HostFontHandler::SetInstance(IGpFontHandler *instance)
{
ms_instance = instance;
}
HostFontHandler *HostFontHandler::GetInstance()
IGpFontHandler *HostFontHandler::GetInstance()
{
return ms_instance;
}
HostFontHandler *HostFontHandler::ms_instance = nullptr;
IGpFontHandler *HostFontHandler::ms_instance = nullptr;
}

View File

@@ -1,23 +1,17 @@
#pragma once
class GpIOStream;
struct IGpFontHandler;
namespace PortabilityLayer
{
class HostFont;
class HostFontHandler
{
public:
virtual void Shutdown() = 0;
virtual HostFont *LoadFont(GpIOStream *stream) = 0;
virtual bool KeepStreamOpen() const = 0;
static void SetInstance(HostFontHandler *instance);
static HostFontHandler *GetInstance();
static void SetInstance(IGpFontHandler *instance);
static IGpFontHandler *GetInstance();
private:
static HostFontHandler *ms_instance;
static IGpFontHandler *ms_instance;
};
}

View File

@@ -1,14 +0,0 @@
#pragma once
namespace PortabilityLayer
{
struct RenderedGlyphMetrics;
class HostFontRenderedGlyph
{
public:
virtual const RenderedGlyphMetrics &GetMetrics() const = 0;
virtual const void *GetData() const = 0;
virtual void Destroy() = 0;
};
}

View File

@@ -3,7 +3,7 @@
#include "FontFamily.h"
#include "FontManager.h"
#include "HostDisplayDriver.h"
#include "HostFont.h"
#include "IGpFont.h"
#include "IGpDisplayDriver.h"
#include "MemoryManager.h"
#include "ResourceManager.h"

View File

@@ -7,7 +7,7 @@
#include "PLQDraw.h"
#include "FontFamily.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "ResolveCachingColor.h"
#include "SimpleGraphic.h"

View File

@@ -6,7 +6,7 @@
#include "MacRomanConversion.h"
#include "MemoryManager.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "PLKeyEncoding.h"
#include "PLQDraw.h"
#include "PLStandardColors.h"

View File

@@ -3,7 +3,7 @@
#include "FontFamily.h"
#include "PLStandardColors.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "ResolveCachingColor.h"
#include <algorithm>

View File

@@ -7,7 +7,7 @@
#include "PLStandardColors.h"
#include "PLTimeTaggedVOSEvent.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "ResolveCachingColor.h"
#include "FontFamily.h"
#include "Vec2i.h"

View File

@@ -13,8 +13,8 @@
#include "PLPasStr.h"
#include "PLStandardColors.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "RenderedGlyphMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "GpRenderedGlyphMetrics.h"
#include "Rect2i.h"
#include "ResourceManager.h"
#include "ResTypeID.h"
@@ -240,7 +240,7 @@ static void DrawGlyph(PixMap *pixMap, const Rect &rect, const Point &penPos, con
{
assert(rect.IsValid());
const PortabilityLayer::RenderedGlyphMetrics *metrics;
const GpRenderedGlyphMetrics *metrics;
const void *data;
if (!rfont->GetGlyph(character, metrics, data))
return;

View File

@@ -3,18 +3,16 @@
#include <stdint.h>
class PLPasStr;
struct GpRenderedFontMetrics;
struct GpRenderedGlyphMetrics;
namespace PortabilityLayer
{
struct RenderedFontMetrics;
struct RenderedGlyphMetrics;
class RenderedFont
{
public:
virtual bool GetGlyph(unsigned int character, const RenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const = 0;
virtual const RenderedFontMetrics &GetMetrics() const = 0;
virtual bool GetGlyph(unsigned int character, const GpRenderedGlyphMetrics *&outMetricsPtr, const void *&outData) const = 0;
virtual const GpRenderedFontMetrics &GetMetrics() const = 0;
virtual size_t MeasureString(const uint8_t *chars, size_t len) const = 0;
virtual bool IsAntiAliased() const = 0;
@@ -28,11 +26,11 @@ namespace PortabilityLayer
#include "PLPasStr.h"
inline size_t PortabilityLayer::RenderedFont::MeasurePStr(const PLPasStr &pstr) const
{
{
return this->MeasureString(pstr.UChars(), pstr.Length());
}
inline size_t PortabilityLayer::RenderedFont::MeasureCharStr(const char *str, size_t len) const
{
{
return this->MeasureString(reinterpret_cast<const uint8_t*>(str), len);
}

View File

@@ -1,13 +0,0 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
struct RenderedFontMetrics
{
int32_t m_ascent;
int32_t m_descent;
int32_t m_linegap;
};
}

View File

@@ -1,18 +0,0 @@
#pragma once
#include <stdint.h>
namespace PortabilityLayer
{
struct RenderedGlyphMetrics
{
size_t m_glyphDataPitch;
uint32_t m_glyphWidth;
uint32_t m_glyphHeight;
int16_t m_bearingX;
int16_t m_bearingY;
int16_t m_advanceX;
};
}

View File

@@ -1,8 +1,8 @@
#include "TextPlacer.h"
#include "PLPasStr.h"
#include "RenderedFontMetrics.h"
#include "RenderedGlyphMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "GpRenderedGlyphMetrics.h"
#include "RenderedFont.h"
#include <assert.h>
@@ -63,7 +63,7 @@ namespace PortabilityLayer
if (character == '\r')
break;
const PortabilityLayer::RenderedGlyphMetrics *metrics = nullptr;
const GpRenderedGlyphMetrics *metrics = nullptr;
const void *glyphData = nullptr;
if (m_rfont->GetGlyph(m_chars[i], metrics, glyphData))
spanWidth += metrics->m_advanceX;
@@ -72,7 +72,7 @@ namespace PortabilityLayer
}
else
{
const PortabilityLayer::RenderedGlyphMetrics *metrics = nullptr;
const GpRenderedGlyphMetrics *metrics = nullptr;
const void *glyphData = nullptr;
if (!m_rfont->GetGlyph(m_chars[i], metrics, glyphData))
{
@@ -116,7 +116,7 @@ namespace PortabilityLayer
outCharacteristics.m_characterIndex = m_currentStartChar + m_emitOffset;
outCharacteristics.m_character = character;
const PortabilityLayer::RenderedGlyphMetrics *metrics;
const GpRenderedGlyphMetrics *metrics;
const void *data;
if (!m_rfont->GetGlyph(character, metrics, data))
{

View File

@@ -2,26 +2,26 @@
#include "Vec2i.h"
class PLPasStr;
class PLPasStr;
struct GpRenderedGlyphMetrics;
namespace PortabilityLayer
{
class RenderedFont;
struct RenderedGlyphMetrics;
struct GlyphPlacementCharacteristics
{
bool m_haveGlyph;
bool m_isParaStart; // Character is the first character in the paragraph
bool m_isParaEnd; // Character is the last character in the paragraph
const RenderedGlyphMetrics *m_glyphMetrics; // Glyph metrics
const GpRenderedGlyphMetrics *m_glyphMetrics; // Glyph metrics
const void *m_glyphData; // Glyph data
Vec2i m_glyphStartPos; // Glyph start position
Vec2i m_glyphEndPos; // Glyph end position
unsigned int m_character; // Character code
size_t m_characterIndex; // Index in the input string
};
class TextPlacer
{
public:

View File

@@ -17,7 +17,7 @@
#include "PLTimeTaggedVOSEvent.h"
#include "Rect2i.h"
#include "RenderedFont.h"
#include "RenderedFontMetrics.h"
#include "GpRenderedFontMetrics.h"
#include "ResolveCachingColor.h"
#include "Vec2i.h"
#include "WindowDef.h"