Skip to content

Commit

Permalink
fonts work, but not using color properly
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtleP committed May 29, 2024
1 parent 1d05f9d commit 66872ae
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 42 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/Nintendo 3DS.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-cmake -S . -B build

- name: Build
run: make -C build
run: catnip -T 3DS

- id: commit
uses: prompt/actions-commit-hash@v3
Expand All @@ -27,8 +24,8 @@ jobs:
with:
name: Nintendo 3DS-${{ steps.commit.outputs.short }}
path: |
build/*.elf
build/*.3dsx
build/**.elf
build/**.3dsx
N3DS-Debug:
runs-on: ubuntu-latest
Expand All @@ -41,11 +38,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build

- name: Build
run: make -C build
run: catnip -T 3DS debug

- id: commit
uses: prompt/actions-commit-hash@v3
Expand Down
18 changes: 6 additions & 12 deletions .github/workflows/Nintendo Switch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S . -B build

- name: Build
run: make -C build
run: catnip -T Switch

- id: commit
uses: prompt/actions-commit-hash@v3
Expand All @@ -27,8 +24,8 @@ jobs:
with:
name: Nintendo Switch-${{ steps.commit.outputs.short }}
path: |
build/*.elf
build/*.nro
build/**.elf
build/**.nro
Switch-Debug:
runs-on: ubuntu-latest
Expand All @@ -41,11 +38,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build

- name: Build
run: make -C build
run: catnip -T Switch debug

- id: commit
uses: prompt/actions-commit-hash@v3
Expand All @@ -54,5 +48,5 @@ jobs:
with:
name: Nintendo Switch (Debug)-${{ steps.commit.outputs.short }}
path: |
build/*.elf
build/*.nro
build/**.elf
build/**.nro
18 changes: 6 additions & 12 deletions .github/workflows/Nintendo Wii U.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -S . -B build

- name: Build
run: make -C build
run: catnipt -T WiiU

- id: commit
uses: prompt/actions-commit-hash@v3
Expand All @@ -27,8 +24,8 @@ jobs:
with:
name: Nintendo Wii U-${{ steps.commit.outputs.short }}
path: |
build/*.elf
build/*.wuhb
build/**.elf
build/**.wuhb
WiiU-Debug:
runs-on: ubuntu-latest
Expand All @@ -41,11 +38,8 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build

- name: Build
run: make -C build
run: catnip -T WiiU debug

- id: commit
uses: prompt/actions-commit-hash@v3
Expand All @@ -54,5 +48,5 @@ jobs:
with:
name: Nintendo Wii U (Debug)-${{ steps.commit.outputs.short }}
path: |
build/*.elf
build/*.wuhb
build/**.elf
build/**.wuhb
9 changes: 9 additions & 0 deletions include/modules/font/Rasterizer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ namespace love
return dpiScale;
}

// clang-format off
STRINGMAP_DECLARE(Hintings, Hinting,
{ "normal", HINTING_NORMAL },
{ "light", HINTING_LIGHT },
{ "mono", HINTING_MONO },
{ "none", HINTING_NONE }
);
// clang-format on

protected:
FontMetrics metrics;
float dpiScale;
Expand Down
4 changes: 2 additions & 2 deletions include/modules/graphics/Graphics.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,8 @@ namespace love
DisplayState()
{}

Color color = Color::WHITE;
Color backgroundColor = Color::BLACK;
Color color = Color(1.0f, 1.0f, 1.0f, 1.0f);
Color backgroundColor = Color(0.0f, 0.0f, 0.0f, 1.0f);

BlendState blend = computeBlendState(BLEND_ALPHA, BLENDALPHA_MULTIPLY);

Expand Down
2 changes: 2 additions & 0 deletions platform/ctr/include/modules/font/Font.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace love
Rasterizer* newTrueTypeRasterizer(Data* data, int size,
const Rasterizer::Settings& settings) const override;

using FontModuleBase::newTrueTypeRasterizer;

private:
static constexpr auto FONT_ARCHIVE_TITLE = 0x0004009B00014002ULL;

Expand Down
5 changes: 4 additions & 1 deletion platform/ctr/source/modules/font/BCFNTRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ namespace love
if (this->size == 0)
throw love::Exception("Invalid font size: {:d}", this->size);

fontFixPointers((CFNT_s*)data->getData());
/* if we already have this data loaded, fixing this (again) is a bad time™ */
if ((uintptr_t)fontGetInfo((CFNT_s*)data->getData())->tglp < (uintptr_t)data->getData())
fontFixPointers((CFNT_s*)data->getData());

auto* fontInfo = fontGetInfo((CFNT_s*)data->getData());
auto* sheetInfo = fontInfo->tglp;
Expand All @@ -94,6 +96,7 @@ namespace love
this->metrics.descent = scaleMetric((fontInfo->height - fontInfo->ascent), this->scale);
this->metrics.height = scaleMetric(sheetInfo->cellHeight, this->scale);

/* todo: more accuracy? */
for (auto map = fontInfo->cmap; map != nullptr; map = map->next)
this->glyphCount += (map->codeEnd - map->codeBegin) + 1;

Expand Down
2 changes: 0 additions & 2 deletions platform/ctr/source/modules/graphics/Texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ namespace love
const auto mipWidth = this->getPixelWidth(level);
const auto mipHeight = this->getPixelHeight(level);

std::printf("Data Size: %zu/Texture Size: %zu\n", size, this->texture->size);

// copy it directly if the size is the whole thing
if (rect == Rect(0, 0, mipWidth, mipHeight))
std::memcpy(textureData, data, size);
Expand Down
53 changes: 52 additions & 1 deletion source/modules/font/wrap_Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,60 @@ int Wrap_FontModule::newRasterizer(lua_State* L)
return newBMFontRasterizer(L);
}

static Rasterizer::Settings luax_checktruetypesettings(lua_State* L, int index)
{
Rasterizer::Settings settings {};

if (lua_type(L, index))
{
const char* hinting = lua_isnoneornil(L, index) ? nullptr : luaL_checkstring(L, index);
if (hinting && !Rasterizer::getConstant(hinting, settings.hinting))
luax_enumerror(L, "Font hinting mode", Rasterizer::Hintings, hinting);

if (!lua_isnoneornil(L, index + 1))
settings.dpiScale.set((float)luaL_checknumber(L, index + 1));
}
else
{
luaL_checktype(L, index, LUA_TTABLE);

lua_getfield(L, index, "hinting");
if (!lua_isnoneornil(L, -1))
{
const char* hinting = luaL_checkstring(L, -1);
if (!Rasterizer::getConstant(hinting, settings.hinting))
luax_enumerror(L, "Font hinting mode", Rasterizer::Hintings, hinting);
}
lua_pop(L, 1);

lua_getfield(L, index, "dpiscale");
if (!lua_isnoneornil(L, -1))
settings.dpiScale.set((float)luaL_checknumber(L, -1));
lua_pop(L, 1);
}

return settings;
}

int Wrap_FontModule::newTrueTypeRasterizer(lua_State* L)
{
return 0;
Rasterizer* rasterizer = nullptr;

if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1))
{
int size = luaL_optinteger(L, 1, 13);
Rasterizer::Settings settings {};

if (!lua_isnoneornil(L, 2))
settings = luax_checktruetypesettings(L, 2);

luax_catchexcept(L, [&] { rasterizer = instance()->newTrueTypeRasterizer(size, settings); });
}

luax_pushtype(L, rasterizer);
rasterizer->release();

return 1;
}

int Wrap_FontModule::newBMFontRasterizer(lua_State* L)
Expand Down
4 changes: 2 additions & 2 deletions source/modules/graphics/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ namespace love
const auto& rasterizer = shaper->getRasterizers()[glyphindex.rasterizerIndex];
dpiScale = rasterizer->getDPIScale();

return rasterizer->getGlyphData(glyphindex.index);
return rasterizer->getGlyphDataForIndex(glyphindex.index);
}

const FontBase::Glyph& FontBase::findGlyph(TextShaper::GlyphIndex glyphindex)
Expand Down Expand Up @@ -295,7 +295,7 @@ namespace love
auto data = graphics->requestBatchedDraw(command);
GlyphVertex* vertexdata = (GlyphVertex*)data.stream;

memcpy(vertexdata, &vertices[cmd.startVertex], sizeof(GlyphVertex) * cmd.vertexCount);
std::copy_n(vertexdata, cmd.vertexCount, &vertices[cmd.startVertex]);
m.transformXY(vertexdata, &vertices[cmd.startVertex], cmd.vertexCount);
}
}
Expand Down

0 comments on commit 66872ae

Please sign in to comment.