Skip to content

Commit

Permalink
v139
Browse files Browse the repository at this point in the history
  • Loading branch information
inanevin committed May 6, 2023
1 parent e5c44fb commit 8bf9143
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ add_library(Lina::VG ALIAS ${PROJECT_NAME})
target_include_directories(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/include)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_MAJOR=1)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_MINOR=3)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_PATCH=8)
target_compile_definitions(${PROJECT_NAME} PUBLIC LINAVG_VERSION_PATCH=9)

#--------------------------------------------------------------------
# Subdirectories & linking
Expand Down
8 changes: 0 additions & 8 deletions include/Core/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,6 @@ namespace LinaVG
/// </summary>
float miterLimit = 150;

/// <summary>
/// If true, texts will be drawn by interpreting each character w/ 32 bit encoding.
/// Set this to true if you want to draw unicode characters.
/// Also you need to load the glyph ranges using customRanges in LoadFont.
/// Do not forget to send your text with in utf8-format, e.g. c++11 > u8"my string"
/// </summary>
bool useUnicodeEncoding = false;

/// <summary>
/// Maximum size a font texture atlas can have, all atlasses are square, so this is used for both width and height.
/// Increase if you are loading a lot of characters or fonts with big sizes (e.g. 100)
Expand Down
1 change: 1 addition & 0 deletions include/Core/Text.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace LinaVG
int m_size = 0;
float m_newLineHeight = 0.0f;
float m_spaceAdvance = 0.0f;
bool m_supportsUnicode = false;
bool m_isSDF = false;
bool m_supportsKerning = false;
LINAVG_MAP<GlyphEncoding, TextCharacter> m_characterGlyphs;
Expand Down
39 changes: 31 additions & 8 deletions src/Core/Drawer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3268,7 +3268,7 @@ namespace LinaVG
characterCount++;
};

if (Config.useUnicodeEncoding)
if (font->m_supportsUnicode)
{
// _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#pragma warning(disable : 4996)
Expand Down Expand Up @@ -3302,15 +3302,38 @@ namespace LinaVG
float totalWidth = 0.0f;
const uint8_t* c;

// Iterate through the whole text and determine max width & height
// As well as line breaks based on wrapping.
for (c = (const uint8_t*)text; *c; c++)
{
auto& ch = font->m_characterGlyphs[*c];
float x = ch.m_advance.x * scale;
float y = ch.m_bearing.y * scale;
auto calcSizeChar = [&](TextCharacter& ch, GlyphEncoding c) {
float x = ch.m_advance.x * scale;
float y = ch.m_bearing.y * scale;
totalWidth += x + spacing;
maxCharacterHeight = Math::Max(maxCharacterHeight, y);
};

if (font->m_supportsUnicode)
{
// _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#pragma warning(disable : 4996)

std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> cv;
auto str32 = cv.from_bytes(text);
std::u32string::iterator it;
int counter = 0;
for (it = str32.begin(); it < str32.end(); it++)
{
auto character = *it;
auto ch = font->m_characterGlyphs[character];
calcSizeChar(ch, character);
counter++;
}
}
else
{
for (c = (uint8_t*)text; *c; c++)
{
auto character = *c;
auto ch = font->m_characterGlyphs[character];
calcSizeChar(ch, character);
}
}

if (font->m_isSDF)
Expand Down
1 change: 1 addition & 0 deletions src/Core/Text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ namespace LinaVG
Backend::BaseBackend::Get()->SaveAPIState();

LinaVGFont* font = new LinaVGFont();
font->m_supportsUnicode = customRanges != nullptr;
font->m_size = size;
font->m_isSDF = loadAsSDF;
font->m_newLineHeight = static_cast<float>(face->size->metrics.height) / 64.0f;
Expand Down

0 comments on commit 8bf9143

Please sign in to comment.