51 lines
2.6 KiB
C++
51 lines
2.6 KiB
C++
#pragma once
|
|
#include "../src/gui/fonts.h"
|
|
#include "../src/gui/hud_card.h"
|
|
|
|
inline void test_lowercase_fonts() {
|
|
ImGui::CreateContext();
|
|
fonts::load();
|
|
auto& io=ImGui::GetIO();
|
|
assert(io.Fonts->FontLoader==ImGuiFreeType::GetFontLoader());
|
|
io.DisplaySize={1280,720};io.DeltaTime=.016f;
|
|
io.BackendFlags|=ImGuiBackendFlags_RendererHasTextures;
|
|
ImGui::NewFrame();
|
|
for(ImFont* font : {fonts::body,fonts::semibold,fonts::label,fonts::heading}) {
|
|
for(float size : {11.f,13.f,14.f,20.f,35.f}) {
|
|
auto* baked=font->GetFontBaked(size);
|
|
for(ImWchar upper='A';upper<='Z';++upper) {
|
|
// Loading the second glyph can grow/reallocate the glyph array.
|
|
const auto* glyph=baked->FindGlyphNoFallback(upper);
|
|
assert(glyph);
|
|
const ImFontGlyph capital=*glyph;
|
|
const auto* lower=baked->FindGlyphNoFallback(upper+('a'-'A'));
|
|
assert(lower && capital.AdvanceX==lower->AdvanceX);
|
|
assert(capital.X0==lower->X0 && capital.X1==lower->X1 && capital.Y0==lower->Y0 && capital.Y1==lower->Y1);
|
|
}
|
|
const auto a=font->CalcTextSizeA(size,FLT_MAX,0,"Macro / Shift / FPS");
|
|
const auto b=font->CalcTextSizeA(size,FLT_MAX,0,"macro / shift / fps");
|
|
assert(a.x==b.x && a.y==b.y);
|
|
}
|
|
}
|
|
assert(fonts::media && fonts::media!=fonts::body);
|
|
auto* media_baked=fonts::media->GetFontBaked(13.f);
|
|
const ImFontGlyph capital=*media_baked->FindGlyphNoFallback('A');
|
|
const ImFontGlyph lower=*media_baked->FindGlyphNoFallback('a');
|
|
assert(capital.U0!=lower.U0 || capital.V0!=lower.V0);
|
|
// Exercise the real hinted fonts at non-integer HUD scales; glyphs and their
|
|
// shadows must fit the card sized by the same font, rather than scaled metrics.
|
|
for(float scale:{.7f,1.f,1.35f,2.5f}) {
|
|
const ImVec2 pos{40,40};const auto bounds=hud_card::size("fps","144",scale,"999");
|
|
auto* draw=ImGui::GetBackgroundDrawList();const int begin=draw->VtxBuffer.Size;
|
|
hud_card::draw(pos,"fps","144",scale,true,IM_COL32_WHITE,"999");
|
|
for(int i=begin;i<draw->VtxBuffer.Size;++i) {
|
|
const auto p=draw->VtxBuffer[i].pos;
|
|
assert(p.x>=pos.x-2 && p.x<=pos.x+bounds.x+2);
|
|
assert(p.y>=pos.y-2 && p.y<=pos.y+bounds.y+2);
|
|
}
|
|
}
|
|
ImGui::EndFrame();ImGui::DestroyContext();
|
|
fonts::body=fonts::semibold=fonts::label=fonts::heading=fonts::media=nullptr;
|
|
std::cout<<"PASS: lowercase glyphs and matching layout at all client font weights and sizes\n";
|
|
}
|