Implement back text rendering (WIP)
This commit is contained in:
@@ -37,7 +37,7 @@ namespace Nz
|
||||
OnFontRelease(this);
|
||||
|
||||
Destroy();
|
||||
SetAtlas(nullptr); // On libère l'atlas proprement
|
||||
SetAtlas({}); // On libère l'atlas proprement
|
||||
}
|
||||
|
||||
void Font::ClearGlyphCache()
|
||||
@@ -81,19 +81,12 @@ namespace Nz
|
||||
OnFontSizeInfoCacheCleared(this);
|
||||
}
|
||||
|
||||
bool Font::Create(FontData* data)
|
||||
bool Font::Create(std::unique_ptr<FontData> data)
|
||||
{
|
||||
NazaraAssert(data, "invalid font data");
|
||||
|
||||
Destroy();
|
||||
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (!data)
|
||||
{
|
||||
NazaraError("Invalid font data");
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
m_data.reset(data);
|
||||
m_data = std::move(data);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -230,7 +223,7 @@ namespace Nz
|
||||
else
|
||||
{
|
||||
NazaraWarning("Failed to extract space character from font, using half the character size");
|
||||
sizeInfo.spaceAdvance = characterSize/2;
|
||||
sizeInfo.spaceAdvance = characterSize / 2;
|
||||
}
|
||||
|
||||
it = m_sizeInfoCache.insert(std::make_pair(characterSize, sizeInfo)).first;
|
||||
@@ -281,13 +274,13 @@ namespace Nz
|
||||
return true;
|
||||
}
|
||||
|
||||
void Font::SetAtlas(const std::shared_ptr<AbstractAtlas>& atlas)
|
||||
void Font::SetAtlas(std::shared_ptr<AbstractAtlas> atlas)
|
||||
{
|
||||
if (m_atlas != atlas)
|
||||
{
|
||||
ClearGlyphCache();
|
||||
|
||||
m_atlas = atlas;
|
||||
m_atlas = std::move(atlas);
|
||||
if (m_atlas)
|
||||
{
|
||||
m_atlasClearedSlot.Connect(m_atlas->OnAtlasCleared, this, &Font::OnAtlasCleared);
|
||||
@@ -380,9 +373,9 @@ namespace Nz
|
||||
return utility->GetFontLoader().LoadFromStream(stream, params);
|
||||
}
|
||||
|
||||
void Font::SetDefaultAtlas(const std::shared_ptr<AbstractAtlas>& atlas)
|
||||
void Font::SetDefaultAtlas(std::shared_ptr<AbstractAtlas> atlas)
|
||||
{
|
||||
s_defaultAtlas = atlas;
|
||||
s_defaultAtlas = std::move(atlas);
|
||||
}
|
||||
|
||||
void Font::SetDefaultGlyphBorder(unsigned int borderSize)
|
||||
@@ -392,13 +385,7 @@ namespace Nz
|
||||
|
||||
void Font::SetDefaultMinimumStepSize(unsigned int minimumStepSize)
|
||||
{
|
||||
#if NAZARA_UTILITY_SAFE
|
||||
if (minimumStepSize == 0)
|
||||
{
|
||||
NazaraError("Minimum step size cannot be zero as it implies division by zero");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
NazaraAssert(minimumStepSize, "minimum step size cannot be zero as it implies a division by zero");
|
||||
|
||||
s_defaultMinimumStepSize = minimumStepSize;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ namespace Nz
|
||||
{
|
||||
class FreeTypeLibrary;
|
||||
|
||||
FT_Library s_library;
|
||||
FT_Stroker s_stroker;
|
||||
FT_Library s_library = nullptr;
|
||||
FT_Stroker s_stroker = nullptr;
|
||||
std::shared_ptr<FreeTypeLibrary> s_libraryOwner;
|
||||
constexpr float s_scaleFactor = 1 << 6;
|
||||
constexpr float s_invScaleFactor = 1.f / s_scaleFactor;
|
||||
@@ -427,20 +427,17 @@ namespace Nz
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> font = std::make_shared<Font>();
|
||||
if (font->Create(face.get()))
|
||||
{
|
||||
face.release();
|
||||
return font;
|
||||
}
|
||||
else
|
||||
if (!font->Create(std::move(face)))
|
||||
return nullptr;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> LoadMemory(const void* data, std::size_t size, const FontParams& parameters)
|
||||
{
|
||||
NazaraUnused(parameters);
|
||||
|
||||
std::unique_ptr<FreeTypeStream> face(new FreeTypeStream);
|
||||
std::unique_ptr<FreeTypeStream> face = std::make_unique<FreeTypeStream>();
|
||||
face->SetMemory(data, size);
|
||||
|
||||
if (!face->Open())
|
||||
@@ -450,13 +447,10 @@ namespace Nz
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> font = std::make_shared<Font>();
|
||||
if (font->Create(face.get()))
|
||||
{
|
||||
face.release();
|
||||
return font;
|
||||
}
|
||||
else
|
||||
if (!font->Create(std::move(face)))
|
||||
return nullptr;
|
||||
|
||||
return font;
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> LoadStream(Stream& stream, const FontParams& parameters)
|
||||
@@ -473,13 +467,10 @@ namespace Nz
|
||||
}
|
||||
|
||||
std::shared_ptr<Font> font = std::make_shared<Font>();
|
||||
if (font->Create(face.get()))
|
||||
{
|
||||
face.release();
|
||||
return font;
|
||||
}
|
||||
else
|
||||
if (!font->Create(std::move(face)))
|
||||
return nullptr;
|
||||
|
||||
return font;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -73,9 +73,9 @@ namespace Nz
|
||||
return m_layers.size();
|
||||
}
|
||||
|
||||
UInt32 GuillotineImageAtlas::GetStorage() const
|
||||
DataStoreFlags GuillotineImageAtlas::GetStorage() const
|
||||
{
|
||||
return static_cast<UInt32>(DataStorage::Software);
|
||||
return DataStorage::Software;
|
||||
}
|
||||
|
||||
bool GuillotineImageAtlas::Insert(const Image& image, Rectui* rect, bool* flipped, unsigned int* layerIndex)
|
||||
@@ -159,30 +159,23 @@ namespace Nz
|
||||
m_rectSplitHeuristic = heuristic;
|
||||
}
|
||||
|
||||
AbstractImage* GuillotineImageAtlas::ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const
|
||||
std::shared_ptr<AbstractImage> GuillotineImageAtlas::ResizeImage(const std::shared_ptr<AbstractImage>& oldImage, const Vector2ui& size) const
|
||||
{
|
||||
std::unique_ptr<Image> newImage(new Image(ImageType::E2D, PixelFormat::A8, size.x, size.y));
|
||||
std::shared_ptr<Image> newImage = std::make_shared<Image>(ImageType::E2D, PixelFormat::A8, size.x, size.y);
|
||||
if (oldImage)
|
||||
{
|
||||
newImage->Copy(static_cast<Image&>(*oldImage), Rectui(size), Vector2ui(0, 0)); // Copie des anciennes données
|
||||
}
|
||||
|
||||
return newImage.release();
|
||||
return newImage;
|
||||
}
|
||||
|
||||
bool GuillotineImageAtlas::ResizeLayer(Layer& layer, const Vector2ui& size)
|
||||
{
|
||||
AbstractImage* oldLayer = layer.image.get();
|
||||
|
||||
std::unique_ptr<AbstractImage> newImage(ResizeImage(layer.image.get(), size));
|
||||
std::shared_ptr<AbstractImage> newImage = ResizeImage(layer.image, size);
|
||||
if (!newImage)
|
||||
return false; // Nous n'avons pas pu allouer
|
||||
|
||||
if (newImage.get() == oldLayer) // Le layer a été agrandi dans le même objet, pas de souci
|
||||
{
|
||||
newImage.release(); // On possède déjà un unique_ptr sur cette ressource
|
||||
if (newImage == layer.image) // Le layer a été agrandi dans le même objet, pas de souci
|
||||
return true;
|
||||
}
|
||||
|
||||
// On indique à ceux que ça intéresse qu'on a changé de pointeur
|
||||
// (chose très importante pour ceux qui le stockent)
|
||||
|
||||
Reference in New Issue
Block a user