-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
26 lines (21 loc) · 736 Bytes
/
main.cpp
File metadata and controls
26 lines (21 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <fstream>
#include "FontParser.h"
#include "FrameBufferCanvas.h"
#include "utils/Unicode.h"
int main() {
// Settings
FontParser reader("fonts/NotoSansJP-Regular.ttf");
const auto cps = utf8ToCodepoints("ほげ");
constexpr int height = 800;
// Get font metric data
const auto [ascent, descent] = reader.getFontMetric();
const float scale = static_cast<float>(height) / (ascent - descent);
// Get glyphs and the necessary total width
const auto [glyphs, width] = reader.getGlyphs(cps, scale);
// Initialize canvas and render glyphs
FrameBufferCanvas canvas{width, height};
canvas.setGlyphBaseline(ascent);
canvas.setScale(scale);
canvas.renderGlyphs(glyphs);
canvas.writePngFile("out.png");
}