Skip to content

Commit

Permalink
the issue #7 show than the Glyph ReScale in merged mode can produce a…
Browse files Browse the repository at this point in the history
… bad font format.

not in all case (not seen with my fonts), but can
so just added an option for disable it in generator settings,
 if the user ensure than he not want glyph rescale
just a little help, the time to analyse what is wrong. can take some time
  • Loading branch information
aiekick committed May 12, 2020
1 parent 9e83be1 commit 620e962
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 10 deletions.
2 changes: 1 addition & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(int, char**argv)
static const ImWchar icons_ranges[] = { ICON_MIN_IGFS, ICON_MAX_IGFS, 0 };
ImFontConfig icons_config; icons_config.MergeMode = true; icons_config.PixelSnapH = true;
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedBase85TTF(FONT_ICON_BUFFER_NAME_IGFS, 15.0f, &icons_config, icons_ranges);

MainFrame::Instance(mainWindow)->Init();

// Main loop
Expand Down
12 changes: 7 additions & 5 deletions src/Generator/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ void Generator::GenerateFontFile_Merged(
// abse infos for merge all toher fonts in this one
for (auto &it : vProjectFile->m_Fonts)
{
if (vProjectFile->m_FontToMergeIn == it.second.m_FontFileName)
if (vProjectFile->m_FontToMergeIn == it.second.m_FontFileName &&
!vProjectFile->IsGenMode(GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE))
{
baseFontBoundingBox = it.second.m_BoundingBox;
baseFontAscent = it.second.m_Ascent;
Expand All @@ -533,7 +534,8 @@ void Generator::GenerateFontFile_Merged(
{
bool scaleChanged = false;
ct::dvec2 scale = 1.0;
if (vProjectFile->m_FontToMergeIn != it.second.m_FontFileName)
if (vProjectFile->m_FontToMergeIn != it.second.m_FontFileName &&
!vProjectFile->IsGenMode(GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE))
{
scaleChanged = true;
ct::ivec2 newSize = it.second.m_BoundingBox.zw() - it.second.m_BoundingBox.xy();
Expand All @@ -554,17 +556,17 @@ void Generator::GenerateFontFile_Merged(
newHeaderNames[glyph.first] = gInfos.newHeaderName;
newCodePoints[glyph.first] = gInfos.newCodePoint;

if (scaleChanged)
if (scaleChanged &&
!vProjectFile->IsGenMode(GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE))
{
gInfos.simpleGlyph.isValid = true;
gInfos.simpleGlyph.m_Scale = scale;

gInfos.m_FontBoundingBox = baseFontBoundingBox;
gInfos.m_FontAscent = baseFontAscent;
gInfos.m_FontDescent = baseFontDescent;

}

newGlyphInfos[glyph.first] = gInfos;
}

Expand Down
7 changes: 4 additions & 3 deletions src/Generator/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ enum _GenModeFlags
GENERATOR_MODE_CURRENT = (1 << 3),
GENERATOR_MODE_BATCH = (1 << 4),
GENERATOR_MODE_MERGED = (1 << 5),
GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_NAMES = (1 << 6),
GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_CODEPOINT = (1 << 7),
GENERATOR_MODE_FONT_SETTINGS_USE_POST_TABLES = (1 << 8),
GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE = (1 << 6),
GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_NAMES = (1 << 7),
GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_CODEPOINT = (1 << 8),
GENERATOR_MODE_FONT_SETTINGS_USE_POST_TABLES = (1 << 9),
GENERATOR_MODE_RADIO_FONT_CPP = GENERATOR_MODE_FONT | GENERATOR_MODE_CPP, // for raido widgets
GENERATOR_MODE_RADIO_CUR_BAT_MER = GENERATOR_MODE_CURRENT | GENERATOR_MODE_BATCH | GENERATOR_MODE_MERGED, // for radio widgets
GENERATOR_MODE_RADIO_CDP_NAMES = GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_CODEPOINT | GENERATOR_MODE_HEADER_SETTINGS_ORDER_BY_NAMES, // for radio widgets
Expand Down
3 changes: 2 additions & 1 deletion src/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ void MainFrame::Init()

#ifdef _DEBUG
std::string projectPath = PROJECT_PATH;
LoadProject(projectPath + "\\projects\\ImGuiFontStudio.ifs"); // directly open this project file
//LoadProject(projectPath + "\\projects\\ImGuiFontStudio.ifs"); // directly open this project file
LoadProject(projectPath + "\\bug\\2020_05_12\\filemenu.ifs");
#endif

GuiLayout::Instance()->Init();
Expand Down
18 changes: 18 additions & 0 deletions src/Panes/GeneratorPane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,12 @@ int GeneratorPane::DrawFontsGenerator(ProjectFile *vProjectFile, int vWidgetId)
}
if (ImGui::Button("Quick Font Merged"))
{
bool disableGlyphReScale = vProjectFile->IsGenMode(GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE);
vProjectFile->m_GenMode = (GenModeFlags)0;
vProjectFile->AddGenMode(GENERATOR_MODE_MERGED_FONT); // font + header
vProjectFile->AddGenMode(GENERATOR_MODE_FONT_SETTINGS_USE_POST_TABLES);
if (disableGlyphReScale)
vProjectFile->AddGenMode(GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE);
std::string path = FileHelper::Instance()->GetAppPath() + "/exports";
path = FileHelper::Instance()->CorrectFilePathName(path);
FileHelper::Instance()->CreateDirectoryIfNotExist(path);
Expand Down Expand Up @@ -197,6 +200,21 @@ int GeneratorPane::DrawFontsGenerator(ProjectFile *vProjectFile, int vWidgetId)
ImGui::Unindent();

ImGui::Text("Settings : ");
if (vProjectFile->IsGenMode(GENERATOR_MODE_MERGED))
{
ImGui::Indent();
{
ImGui::Text("Merged Mode : ");
ImGui::Indent();
{
change |= ImGui::RadioButtonLabeled_BitWize<GenModeFlags>(
"Disable Glyph Re Write", "if your fonts have same size,\nit can be more safe for the moment (bad generated font is some case)\nto disable glyph re write.\nonly needed if we must change glyph scale",
&vProjectFile->m_GenMode, GENERATOR_MODE_MERGED_SETTINGS_DISABLE_GLYPH_RESCALE, 50.0f);
}
ImGui::Unindent();
}
ImGui::Unindent();
}
if (vProjectFile->IsGenMode(GENERATOR_MODE_HEADER))
{
ImGui::Indent();
Expand Down

0 comments on commit 620e962

Please sign in to comment.