Repository navigation
Expand file tree
/
Copy pathcomposer.cpp
More file actions
104 lines (90 loc) · 3.01 KB
/
Copy pathcomposer.cpp
File metadata and controls
104 lines (90 loc) · 3.01 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* Copyright (C) 2026 Shitty team
* MIT licensed
* See the file LICENSE.MIT for the full license.
*/
#include "composer.h"
#include "options.h"
#include "listener.h"
#include "font_path.h"
#include "input_router.h"
#include "font_resolver.h"
#include "input_bindings.h"
#include "font_fontconfig.h"
#include "poller.h"
#include <std/alg/minmax.h>
#include <std/dbg/assert.h>
using namespace stl;
Composer::Composer(ObjPool* pool_)
: pool(pool_)
{
poller = Poller::create(*this);
input = createInputRouter(*this);
inputBindings = InputBindings::create(*this);
createFontconfigResolver(*this);
createPathFontResolver(*this);
}
void Composer::setContentScale(float scale) {
STD_ASSERT(scale > 0.0f);
if (contentScale == scale) {
return;
}
contentScale = scale;
for (IntrusiveNode* node = contentScaleChangedListeners.mutFront(); node != contentScaleChangedListeners.mutEnd();) {
Listener* const listener = static_cast<Listener*>(node);
node = node->next;
listener->onListen();
}
}
void Composer::setGlyphSize(u16 width, u16 height) {
STD_ASSERT(width != 0);
STD_ASSERT(height != 0);
if (glyphWidth == width && glyphHeight == height) {
return;
}
glyphWidth = width;
glyphHeight = height;
}
void Composer::setCellExtras(CellExtraStore* extras) {
if (cellExtras == extras) {
return;
}
cellExtras = extras;
for (IntrusiveNode* node = cellExtrasChangedListeners.mutFront(); node != cellExtrasChangedListeners.mutEnd();) {
Listener* const listener = static_cast<Listener*>(node);
node = node->next;
listener->onListen();
}
}
void Composer::resize(u16 pixelWidth_, u16 pixelHeight_) {
STD_ASSERT(glyphWidth != 0);
STD_ASSERT(glyphHeight != 0);
const u32 border = 2u * opts.border;
const u32 contentWidth = pixelWidth_ > border ? pixelWidth_ - border : 0;
const u32 contentHeight = pixelHeight_ > border ? pixelHeight_ - border : 0;
const u16 columns_ = (u16)(max<u32>(1, contentWidth / glyphWidth));
const u16 rows_ = (u16)(max<u32>(1, contentHeight / glyphHeight));
if (columns == columns_ && rows == rows_ && pixelWidth == pixelWidth_ && pixelHeight == pixelHeight_) {
return;
}
columns = columns_;
rows = rows_;
pixelWidth = pixelWidth_;
pixelHeight = pixelHeight_;
for (IntrusiveNode* node = resizedListeners.mutFront(); node != resizedListeners.mutEnd();) {
Listener* const listener = static_cast<Listener*>(node);
node = node->next;
listener->onListen();
}
}
Font* Composer::loadFont(ObjPool& owner, const FontRequest& request, FontMetrics& metrics) {
for (IntrusiveNode* node = fontResolvers.mutFront(); node != fontResolvers.mutEnd();) {
FontResolver* const resolver = static_cast<FontResolver*>(node);
node = node->next;
Font* const font = resolver->load(owner, request, metrics);
if (font != nullptr) {
return font;
}
}
return nullptr;
}