-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwiFont.cpp
723 lines (615 loc) · 19.3 KB
/
wiFont.cpp
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
#include "wiFont.h"
#include "wiRenderer.h"
#include "wiResourceManager.h"
#include "wiHelper.h"
#include "shaders/ResourceMapping.h"
#include "shaders/ShaderInterop_Font.h"
#include "wiBackLog.h"
#include "wiTextureHelper.h"
#include "wiRectPacker.h"
#include "wiSpinLock.h"
#include "wiPlatform.h"
#include "wiEvent.h"
#include "Utility/arial.h"
#include "Utility/stb_truetype.h"
#include <fstream>
#include <atomic>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <string>
using namespace wiGraphics;
using namespace wiRectPacker;
#define WHITESPACE_SIZE ((float(params.size) + params.spacingX) * params.scaling * 0.25f)
#define TAB_SIZE (WHITESPACE_SIZE * 4)
#define LINEBREAK_SIZE ((float(params.size) + params.spacingY) * params.scaling)
namespace wiFont_Internal
{
GPUBuffer constantBuffer;
BlendState blendState;
RasterizerState rasterizerState;
DepthStencilState depthStencilState;
Sampler sampler;
InputLayout inputLayout;
Shader vertexShader;
Shader pixelShader;
PipelineState PSO;
wiCanvas canvases[COMMANDLIST_COUNT];
std::atomic_bool initialized { false };
Texture texture;
struct Glyph
{
float x;
float y;
float width;
float height;
uint16_t tc_left;
uint16_t tc_right;
uint16_t tc_top;
uint16_t tc_bottom;
};
std::unordered_map<int32_t, Glyph> glyph_lookup;
std::unordered_map<int32_t, rect_xywh> rect_lookup;
// pack glyph identifiers to a 32-bit hash:
// height: 10 bits (height supported: 0 - 1023)
// style: 6 bits (number of font styles supported: 0 - 63)
// code: 16 bits (character code range supported: 0 - 65535)
constexpr int32_t glyphhash(int code, int style, int height) { return ((code & 0xFFFF) << 16) | ((style & 0x3F) << 10) | (height & 0x3FF); }
constexpr int codefromhash(int64_t hash) { return int((hash >> 16) & 0xFFFF); }
constexpr int stylefromhash(int64_t hash) { return int((hash >> 10) & 0x3F); }
constexpr int heightfromhash(int64_t hash) { return int((hash >> 0) & 0x3FF); }
std::unordered_set<int32_t> pendingGlyphs;
wiSpinLock glyphLock;
struct wiFontStyle
{
std::string name;
std::vector<uint8_t> fontBuffer; // only used if loaded from file, need to keep alive
stbtt_fontinfo fontInfo;
int ascent, descent, lineGap;
void Create(const std::string& newName, const uint8_t* data, size_t size)
{
name = newName;
int offset = stbtt_GetFontOffsetForIndex(data, 0);
if (!stbtt_InitFont(&fontInfo, data, offset))
{
std::string error = "Failed to load font: " + name + " (file was unrecognized, it must be a .ttf file)";
wiBackLog::post(error.c_str());
}
stbtt_GetFontVMetrics(&fontInfo, &ascent, &descent, &lineGap);
}
void Create(const std::string& newName)
{
if (wiHelper::FileRead(newName, fontBuffer))
{
Create(newName, fontBuffer.data(), fontBuffer.size());
}
else
{
std::string error = "Failed to load font: " + name + " (file could not be opened)";
wiBackLog::post(error.c_str());
}
}
};
std::vector<wiFontStyle> fontStyles;
struct FontVertex
{
XMFLOAT2 Pos;
XMHALF2 Tex;
};
template<typename T>
uint32_t WriteVertices(volatile FontVertex* vertexList, const T* text, wiFontParams params)
{
const wiFontStyle& fontStyle = fontStyles[params.style];
const float fontScale = stbtt_ScaleForPixelHeight(&fontStyle.fontInfo, (float)params.size);
uint32_t quadCount = 0;
float line = 0;
float pos = 0;
float pos_last_letter = 0;
size_t last_word_begin = 0;
bool start_new_word = false;
auto word_wrap = [&] {
start_new_word = true;
if (last_word_begin > 0 && params.h_wrap >= 0 && pos >= params.h_wrap - 1)
{
// Word ended and wrap detected, push down last word by one line:
float word_offset = vertexList[last_word_begin].Pos.x;
for (size_t i = last_word_begin; i < quadCount * 4; ++i)
{
vertexList[i].Pos.x -= word_offset;
vertexList[i].Pos.y += LINEBREAK_SIZE;
}
line += LINEBREAK_SIZE;
pos -= word_offset;
}
};
int code_prev = 0;
size_t i = 0;
while(text[i] != 0)
{
T character = text[i++];
int code = (int)character;
const int32_t hash = glyphhash(code, params.style, params.size);
if (glyph_lookup.count(hash) == 0)
{
// glyph not packed yet, so add to pending list:
glyphLock.lock();
pendingGlyphs.insert(hash);
glyphLock.unlock();
continue;
}
if (code == '\n')
{
word_wrap();
line += LINEBREAK_SIZE;
pos = 0;
code_prev = 0;
}
else if (code == ' ')
{
word_wrap();
pos += WHITESPACE_SIZE;
start_new_word = true;
code_prev = 0;
}
else if (code == '\t')
{
word_wrap();
pos += TAB_SIZE;
start_new_word = true;
code_prev = 0;
}
else
{
const Glyph& glyph = glyph_lookup.at(hash);
const float glyphWidth = glyph.width * params.scaling;
const float glyphHeight = glyph.height * params.scaling;
const float glyphOffsetX = glyph.x * params.scaling;
const float glyphOffsetY = glyph.y * params.scaling;
const size_t vertexID = size_t(quadCount) * 4;
if (start_new_word)
{
last_word_begin = vertexID;
}
start_new_word = false;
if (code_prev != 0)
{
int kern = stbtt_GetCodepointKernAdvance(&fontStyle.fontInfo, code_prev, code);
pos += kern * fontScale;
}
code_prev = code;
const float left = pos + glyphOffsetX;
const float right = left + glyphWidth;
const float top = line + glyphOffsetY;
const float bottom = top + glyphHeight;
vertexList[vertexID + 0].Pos.x = left;
vertexList[vertexID + 0].Pos.y = top;
vertexList[vertexID + 1].Pos.x = right;
vertexList[vertexID + 1].Pos.y = top;
vertexList[vertexID + 2].Pos.x = left;
vertexList[vertexID + 2].Pos.y = bottom;
vertexList[vertexID + 3].Pos.x = right;
vertexList[vertexID + 3].Pos.y = bottom;
vertexList[vertexID + 0].Tex.x = glyph.tc_left;
vertexList[vertexID + 0].Tex.y = glyph.tc_top;
vertexList[vertexID + 1].Tex.x = glyph.tc_right;
vertexList[vertexID + 1].Tex.y = glyph.tc_top;
vertexList[vertexID + 2].Tex.x = glyph.tc_left;
vertexList[vertexID + 2].Tex.y = glyph.tc_bottom;
vertexList[vertexID + 3].Tex.x = glyph.tc_right;
vertexList[vertexID + 3].Tex.y = glyph.tc_bottom;
pos += glyph.width * params.scaling + params.spacingX;
pos_last_letter = pos;
quadCount++;
}
}
word_wrap();
return quadCount;
}
}
using namespace wiFont_Internal;
namespace wiFont
{
void LoadShaders()
{
std::string path = wiRenderer::GetShaderPath();
wiRenderer::LoadShader(VS, vertexShader, "fontVS.cso");
pixelShader.auto_samplers.emplace_back();
pixelShader.auto_samplers.back().sampler = sampler;
pixelShader.auto_samplers.back().slot = SSLOT_ONDEMAND1;
wiRenderer::LoadShader(PS, pixelShader, "fontPS.cso");
PipelineStateDesc desc;
desc.vs = &vertexShader;
desc.ps = &pixelShader;
desc.bs = &blendState;
desc.dss = &depthStencilState;
desc.rs = &rasterizerState;
desc.pt = TRIANGLESTRIP;
wiRenderer::GetDevice()->CreatePipelineState(&desc, &PSO);
}
void Initialize()
{
if (initialized)
{
return;
}
// add default font if there is none yet:
if (fontStyles.empty())
{
AddFontStyle("arial", arial, sizeof(arial));
}
GraphicsDevice* device = wiRenderer::GetDevice();
{
GPUBufferDesc bd;
bd.Usage = USAGE_DYNAMIC;
bd.ByteWidth = sizeof(FontCB);
bd.BindFlags = BIND_CONSTANT_BUFFER;
bd.CPUAccessFlags = CPU_ACCESS_WRITE;
device->CreateBuffer(&bd, nullptr, &constantBuffer);
}
RasterizerState rs;
rs.FillMode = FILL_SOLID;
rs.CullMode = CULL_FRONT;
rs.FrontCounterClockwise = true;
rs.DepthBias = 0;
rs.DepthBiasClamp = 0;
rs.SlopeScaledDepthBias = 0;
rs.DepthClipEnable = false;
rs.MultisampleEnable = false;
rs.AntialiasedLineEnable = false;
rasterizerState = rs;
BlendState bd;
bd.RenderTarget[0].BlendEnable = true;
bd.RenderTarget[0].SrcBlend = BLEND_SRC_ALPHA;
bd.RenderTarget[0].DestBlend = BLEND_INV_SRC_ALPHA;
bd.RenderTarget[0].BlendOp = BLEND_OP_ADD;
bd.RenderTarget[0].SrcBlendAlpha = BLEND_ONE;
bd.RenderTarget[0].DestBlendAlpha = BLEND_ONE;
bd.RenderTarget[0].BlendOpAlpha = BLEND_OP_ADD;
bd.RenderTarget[0].RenderTargetWriteMask = COLOR_WRITE_ENABLE_ALL;
bd.IndependentBlendEnable = false;
blendState = bd;
DepthStencilState dsd;
dsd.DepthEnable = false;
dsd.StencilEnable = false;
depthStencilState = dsd;
SamplerDesc samplerDesc;
samplerDesc.Filter = FILTER_MIN_MAG_LINEAR_MIP_POINT;
samplerDesc.AddressU = TEXTURE_ADDRESS_BORDER;
samplerDesc.AddressV = TEXTURE_ADDRESS_BORDER;
samplerDesc.AddressW = TEXTURE_ADDRESS_BORDER;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 0;
samplerDesc.ComparisonFunc = COMPARISON_NEVER;
samplerDesc.BorderColor[0] = 0;
samplerDesc.BorderColor[1] = 0;
samplerDesc.BorderColor[2] = 0;
samplerDesc.BorderColor[3] = 0;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = FLT_MAX;
device->CreateSampler(&samplerDesc, &sampler);
static wiEvent::Handle handle1 = wiEvent::Subscribe(SYSTEM_EVENT_RELOAD_SHADERS, [](uint64_t userdata) { LoadShaders(); });
LoadShaders();
wiBackLog::post("wiFont Initialized");
initialized.store(true);
}
void UpdatePendingGlyphs()
{
glyphLock.lock();
// If there are pending glyphs, render them and repack the atlas:
if (!pendingGlyphs.empty())
{
// Pad the glyph rects in the atlas to avoid bleeding from nearby texels:
const int borderPadding = 1;
// Font resolution is upscaled to make it sharper:
const float upscaling = 2.0f;//std::max(2.0f, wiRenderer::GetDevice()->GetDPIScaling());
for (int32_t hash : pendingGlyphs)
{
const int code = codefromhash(hash);
const int style = stylefromhash(hash);
const float height = (float)heightfromhash(hash) * upscaling;
wiFontStyle& fontStyle = fontStyles[style];
float fontScaling = stbtt_ScaleForPixelHeight(&fontStyle.fontInfo, height);
// get bounding box for character (may be offset to account for chars that dip above or below the line
int left, top, right, bottom;
stbtt_GetCodepointBitmapBox(&fontStyle.fontInfo, code, fontScaling, fontScaling, &left, &top, &right, &bottom);
// Glyph dimensions are calculated without padding:
Glyph& glyph = glyph_lookup[hash];
glyph.x = float(left);
glyph.y = float(top) + float(fontStyle.ascent) * fontScaling;
glyph.width = float(right - left);
glyph.height = float(bottom - top);
// Remove dpi upscaling:
glyph.x = glyph.x / upscaling;
glyph.y = glyph.y / upscaling;
glyph.width = glyph.width / upscaling;
glyph.height = glyph.height / upscaling;
// Add padding to the rectangle that will be packed in the atlas:
right += borderPadding * 2;
bottom += borderPadding * 2;
rect_lookup[hash] = rect_ltrb(left, top, right, bottom);
}
pendingGlyphs.clear();
// This reference array will be used for packing:
std::vector<rect_xywh*> out_rects;
out_rects.reserve(rect_lookup.size());
for (auto& it : rect_lookup)
{
out_rects.push_back(&it.second);
}
// Perform packing and process the result if successful:
std::vector<bin> bins;
if (pack(out_rects.data(), (int)out_rects.size(), 4096, bins))
{
assert(bins.size() == 1 && "The regions won't fit into one texture!");
// Retrieve texture atlas dimensions:
const int bitmapWidth = bins[0].size.w;
const int bitmapHeight = bins[0].size.h;
const float inv_width = 1.0f / bitmapWidth;
const float inv_height = 1.0f / bitmapHeight;
// Create the CPU-side texture atlas and fill with transparency (0):
std::vector<uint8_t> bitmap(size_t(bitmapWidth) * size_t(bitmapHeight));
std::fill(bitmap.begin(), bitmap.end(), 0);
// Iterate all packed glyph rectangles:
for (auto it : rect_lookup)
{
const int32_t hash = it.first;
const wchar_t code = codefromhash(hash);
const int style = stylefromhash(hash);
const float height = (float)heightfromhash(hash) * upscaling;
const wiFontStyle& fontStyle = fontStyles[style];
rect_xywh& rect = it.second;
Glyph& glyph = glyph_lookup[hash];
// Remove border padding from the packed rectangle (we don't want to touch the border, it should stay transparent):
rect.x += borderPadding;
rect.y += borderPadding;
rect.w -= borderPadding * 2;
rect.h -= borderPadding * 2;
float fontScaling = stbtt_ScaleForPixelHeight(&fontStyle.fontInfo, height);
// Render the glyph inside the CPU-side atlas:
int byteOffset = rect.x + (rect.y * bitmapWidth);
stbtt_MakeCodepointBitmap(&fontStyle.fontInfo, bitmap.data() + byteOffset, rect.w, rect.h, bitmapWidth, fontScaling, fontScaling, code);
// Compute texture coordinates for the glyph:
float tc_left = float(rect.x);
float tc_right = tc_left + float(rect.w);
float tc_top = float(rect.y);
float tc_bottom = tc_top + float(rect.h);
tc_left *= inv_width;
tc_right *= inv_width;
tc_top *= inv_height;
tc_bottom *= inv_height;
glyph.tc_left = XMConvertFloatToHalf(tc_left);
glyph.tc_right = XMConvertFloatToHalf(tc_right);
glyph.tc_top = XMConvertFloatToHalf(tc_top);
glyph.tc_bottom = XMConvertFloatToHalf(tc_bottom);
}
// Upload the CPU-side texture atlas bitmap to the GPU:
wiTextureHelper::CreateTexture(texture, bitmap.data(), bitmapWidth, bitmapHeight, FORMAT_R8_UNORM);
}
}
glyphLock.unlock();
}
const Texture* GetAtlas()
{
return &texture;
}
int AddFontStyle(const std::string& fontName)
{
for (size_t i = 0; i < fontStyles.size(); i++)
{
const wiFontStyle& fontStyle = fontStyles[i];
if (!fontStyle.name.compare(fontName))
{
return int(i);
}
}
fontStyles.emplace_back();
fontStyles.back().Create(fontName);
return int(fontStyles.size() - 1);
}
int AddFontStyle(const std::string& fontName, const uint8_t* data, size_t size)
{
for (size_t i = 0; i < fontStyles.size(); i++)
{
const wiFontStyle& fontStyle = fontStyles[i];
if (!fontStyle.name.compare(fontName))
{
return int(i);
}
}
fontStyles.emplace_back();
fontStyles.back().Create(fontName, data, size);
return int(fontStyles.size() - 1);
}
template<typename T>
float textWidth_internal(const T* text, const wiFontParams& params)
{
if (params.style >= (int)fontStyles.size())
{
return 0;
}
float maxWidth = 0;
float currentLineWidth = 0;
size_t i = 0;
while (text[i] != 0)
{
int code = (int)text[i++];
const int32_t hash = glyphhash(code, params.style, params.size);
if (glyph_lookup.count(hash) == 0)
{
// glyph not packed yet, we just continue (it will be added if it is actually rendered)
continue;
}
if (code == '\n')
{
currentLineWidth = 0;
}
else if (code == ' ')
{
currentLineWidth += WHITESPACE_SIZE;
}
else if (code == '\t')
{
currentLineWidth += TAB_SIZE;
}
else
{
const Glyph& glyph = glyph_lookup.at(hash);
currentLineWidth += glyph.width + float(params.spacingX) * params.scaling;
}
maxWidth = std::max(maxWidth, currentLineWidth);
}
return maxWidth;
}
template<typename T>
float textHeight_internal(const T* text, const wiFontParams& params)
{
if (params.style >= (int)fontStyles.size())
{
return 0;
}
float height = LINEBREAK_SIZE;
size_t i = 0;
while (text[i] != 0)
{
int code = (int)text[i++];
if (code == '\n')
{
height += LINEBREAK_SIZE;
}
}
return height;
}
template<typename T>
void Draw_internal(const T* text, size_t text_length, const wiFontParams& params, CommandList cmd)
{
if (text_length <= 0 || !initialized.load())
{
return;
}
wiFontParams newProps = params;
if (params.h_align == WIFALIGN_CENTER)
newProps.posX -= textWidth_internal(text, newProps) / 2;
else if (params.h_align == WIFALIGN_RIGHT)
newProps.posX -= textWidth_internal(text, newProps);
if (params.v_align == WIFALIGN_CENTER)
newProps.posY -= textHeight_internal(text, newProps) / 2;
else if (params.v_align == WIFALIGN_BOTTOM)
newProps.posY -= textHeight_internal(text, newProps);
GraphicsDevice* device = wiRenderer::GetDevice();
GraphicsDevice::GPUAllocation mem = device->AllocateGPU(sizeof(FontVertex) * text_length * 4, cmd);
if (!mem.IsValid())
{
return;
}
volatile FontVertex* textBuffer = (volatile FontVertex*)mem.data;
const uint32_t quadCount = WriteVertices(textBuffer, text, newProps);
if (quadCount > 0)
{
device->EventBegin("Font", cmd);
device->BindPipelineState(&PSO, cmd);
device->BindConstantBuffer(VS, &constantBuffer, CB_GETBINDSLOT(FontCB), cmd);
device->BindConstantBuffer(PS, &constantBuffer, CB_GETBINDSLOT(FontCB), cmd);
FontCB cb;
cb.g_xFont_BufferOffset = mem.offset;
if (device->CheckCapability(GRAPHICSDEVICE_CAPABILITY_BINDLESS_DESCRIPTORS))
{
cb.g_xFont_TextureIndex = device->GetDescriptorIndex(&texture, SRV);
}
else
{
device->BindResource(PS, &texture, TEXSLOT_FONTATLAS, cmd);
}
device->BindResource(VS, mem.buffer, 0, cmd);
const wiCanvas& canvas = canvases[cmd];
// Asserts will check that a proper canvas was set for this cmd with wiImage::SetCanvas()
// The canvas must be set to have dpi aware rendering
assert(canvas.width > 0);
assert(canvas.height > 0);
assert(canvas.dpi > 0);
const XMMATRIX Projection = canvas.GetProjection();
if (newProps.shadowColor.getA() > 0)
{
// font shadow render:
XMStoreFloat4x4(&cb.g_xFont_Transform,
XMMatrixTranslation((float)newProps.posX + 1, (float)newProps.posY + 1, 0)
* Projection
);
cb.g_xFont_Color = newProps.shadowColor.toFloat4();
device->UpdateBuffer(&constantBuffer, &cb, cmd);
device->DrawInstanced(4, quadCount, 0, 0, cmd);
}
// font base render:
XMStoreFloat4x4(&cb.g_xFont_Transform,
XMMatrixTranslation((float)newProps.posX, (float)newProps.posY, 0)
* Projection
);
cb.g_xFont_Color = newProps.color.toFloat4();
device->UpdateBuffer(&constantBuffer, &cb, cmd);
device->DrawInstanced(4, quadCount, 0, 0, cmd);
device->EventEnd(cmd);
}
UpdatePendingGlyphs();
}
void SetCanvas(const wiCanvas& canvas, wiGraphics::CommandList cmd)
{
canvases[cmd] = canvas;
}
void Draw(const char* text, const wiFontParams& params, CommandList cmd)
{
size_t text_length = strlen(text);
if (text_length == 0)
{
return;
}
Draw_internal(text, text_length, params, cmd);
}
void Draw(const wchar_t* text, const wiFontParams& params, CommandList cmd)
{
size_t text_length = wcslen(text);
if (text_length == 0)
{
return;
}
Draw_internal(text, text_length, params, cmd);
}
void Draw(const std::string& text, const wiFontParams& params, CommandList cmd)
{
Draw_internal(text.c_str(), text.length(), params, cmd);
}
void Draw(const std::wstring& text, const wiFontParams& params, CommandList cmd)
{
Draw_internal(text.c_str(), text.length(), params, cmd);
}
float textWidth(const char* text, const wiFontParams& params)
{
return textWidth_internal(text, params);
}
float textWidth(const wchar_t* text, const wiFontParams& params)
{
return textWidth_internal(text, params);
}
float textWidth(const std::string& text, const wiFontParams& params)
{
return textWidth_internal(text.c_str(), params);
}
float textWidth(const std::wstring& text, const wiFontParams& params)
{
return textWidth_internal(text.c_str(), params);
}
float textHeight(const char* text, const wiFontParams& params)
{
return textHeight_internal(text, params);
}
float textHeight(const wchar_t* text, const wiFontParams& params)
{
return textHeight_internal(text, params);
}
float textHeight(const std::string& text, const wiFontParams& params)
{
return textHeight_internal(text.c_str(), params);
}
float textHeight(const std::wstring& text, const wiFontParams& params)
{
return textHeight_internal(text.c_str(), params);
}
}