Skip to content

Commit 138c0f4

Browse files
author
LocalIdentity
committed
Export generated fonts to their own folder
1 parent d1dfafa commit 138c0f4

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ Release/
88
x64/
99
x86/
1010
ipch/
11+
Generated Fonts/
1112

1213
# Compiled binaries and intermediates
14+
*.exe
1315
*.dll
1416
*.lib
1517
*.obj

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Path of Building Font Generator
2+
3+
This utility builds bitmap fonts used by the Path of Building Community fork. It wraps Windows GDI font rendering into a standalone Win32 application that packs glyphs into `.tga` atlases and emits metadata consumed by the main tool.
4+
5+
## Prerequisites
6+
- Visual Studio 2022 (v143 toolset) with the Desktop development with C++ workload
7+
- Windows 10 SDK (10.0 or newer)
8+
9+
## Building
10+
1. Open `GLFontGen.sln` in Visual Studio.
11+
2. Select the desired configuration (`Release` is recommended for distributing fonts).
12+
3. Build the solution (`Build > Build Solution`).
13+
14+
The resulting executable (`GLFontGen.exe`) stays local to your build environment; it is intentionally not checked into source control.
15+
16+
## Usage
17+
1. Run `GLFontGen.exe`.
18+
2. Pick a font face, weight, and whether to force fixed pitch.
19+
3. Select the font sizes you want to export.
20+
4. Click **Generate**.
21+
22+
Outputs are written to `Generated Fonts/` beside the executable:
23+
24+
- One `.tga` atlas per selected point size (e.g. `Consolas.16.tga`).
25+
- A single `.tgf` metadata file with layout information for every generated height.
26+
27+
## Output Format
28+
- **TGA**: 32-bit BGRA image containing packed glyphs with premultiplied alpha. Dimensions are powers of two chosen to fit the selected glyph set.
29+
- **TGF metadata**:
30+
- Each font size starts with `HEIGHT <px>;`.
31+
- Every glyph line follows `GLYPH <x> <y> <width> <left> <right>` with optional ASCII comment.
32+
- `x`/`y` are the glyph origin inside the atlas, `width` is the advance width in pixels, and `left`/`right` provide side bearings.
33+
34+
Refer to `fontgen.cpp` if you need deeper details or want to extend the format.
35+
36+
## License
37+
Released under the MIT License (see `LICENSE`).

fontgen.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
#include <algorithm>
99
#include <array>
10+
#include <filesystem>
1011
#include <fstream>
1112
#include <iomanip>
1213
#include <sstream>
14+
#include <system_error>
1315
#include <string>
1416
#include <string_view>
1517
#include <vector>
@@ -61,12 +63,16 @@ class glFontGenV2_c {
6163

6264
private:
6365
std::string fontName;
66+
std::filesystem::path outputDir;
6467
std::vector< fontHeight_s > heights;
6568
};
6669

6770
void glFontGenV2_c::Init(const std::string_view i_fontName)
6871
{
6972
fontName = i_fontName;
73+
outputDir = std::filesystem::path("Generated Fonts");
74+
std::error_code ec;
75+
std::filesystem::create_directories(outputDir, ec);
7076
}
7177

7278
void glFontGenV2_c::Build(HDC hdc)
@@ -177,9 +183,10 @@ void glFontGenV2_c::Build(HDC hdc)
177183
}
178184

179185
// Open image file for writing
180-
std::stringstream tgaName;
186+
std::ostringstream tgaName;
181187
tgaName << fontName << "." << height << ".tga";
182-
std::ofstream out(tgaName.str(), std::ios_base::binary);
188+
const auto tgaPath = outputDir / tgaName.str();
189+
std::ofstream out(tgaPath, std::ios_base::binary);
183190
if (!out) {
184191
return;
185192
}
@@ -273,7 +280,8 @@ void glFontGenV2_c::Build(HDC hdc)
273280
void glFontGenV2_c::Finish()
274281
{
275282
// Open info file for writing
276-
std::ofstream tgf(fontName + ".tgf");
283+
const auto tgfPath = outputDir / (fontName + ".tgf");
284+
std::ofstream tgf(tgfPath);
277285
if (!tgf) {
278286
return;
279287
}

0 commit comments

Comments
 (0)