summaryrefslogtreecommitdiff
path: root/src/mir_app/src/FontOptions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mir_app/src/FontOptions.cpp')
-rw-r--r--src/mir_app/src/FontOptions.cpp122
1 files changed, 62 insertions, 60 deletions
diff --git a/src/mir_app/src/FontOptions.cpp b/src/mir_app/src/FontOptions.cpp
index 9c89f7d287..26e6708bff 100644
--- a/src/mir_app/src/FontOptions.cpp
+++ b/src/mir_app/src/FontOptions.cpp
@@ -126,13 +126,12 @@ void UpdateFontSettings(FontIDW *font_id, FontSettingsW *fontsettings);
void UpdateColourSettings(ColourIDW *colour_id, COLORREF *colour);
void UpdateEffectSettings(EffectIDW *effect_id, FONTEFFECT* effectsettings);
-static void WriteLine(FILE *out, const char pszText[])
+static int CompareObj(const MBaseFontObjectW *p1, const MBaseFontObjectW *p2)
{
- fputs(pszText, out);
- fputc('\n', out);
+ return strcmp(p1->dbSettingsGroup, p2->dbSettingsGroup);
}
-static BOOL ExportSettings(HWND hwndDlg, const wchar_t *filename, OBJLIST<FontInternal>& flist, OBJLIST<ColourInternal>& clist, OBJLIST<EffectInternal>& elist)
+static BOOL ExportSettings(HWND hwndDlg, const wchar_t *filename, OBJLIST<FontInternal> &flist, OBJLIST<ColourInternal> &clist, OBJLIST<EffectInternal> &elist)
{
FILE *out = _wfopen(filename, L"w");
if (out == nullptr) {
@@ -145,66 +144,69 @@ static BOOL ExportSettings(HWND hwndDlg, const wchar_t *filename, OBJLIST<FontIn
fputs("SETTINGS:\n\n", out);
- for (auto &F : flist) {
- mir_snprintf(buff, "\n[%s]", F->dbSettingsGroup);
+ LIST<MBaseFontObjectW> arObjects(100, CompareObj);
+ for (auto &it : flist)
+ arObjects.insert(it);
+ for (auto &it : clist)
+ arObjects.insert(it);
+ for (auto &it : elist)
+ arObjects.insert(it);
+
+ for (auto &it : arObjects) {
+ mir_snprintf(buff, "\n[%s]", it->dbSettingsGroup);
if (mir_strcmp(buff, header) != 0) {
strncpy(header, buff, _countof(header));
- WriteLine(out, buff);
+ fputs(buff, out);
+ fputc('\n', out);
}
- fprintf(out, (F->flags & FIDF_APPENDNAME) ? "%sName=s%S\n" : "%s=s%S\n", F->prefix, F->value.szFace);
+ FontInternal *F = (FontInternal*)it;
+ if (flist.indexOf(F) != -1) {
+ fprintf(out, (F->flags & FIDF_APPENDNAME) ? "%sName=s%S\n" : "%s=s%S\n", F->setting, F->value.szFace);
- int iFontSize;
- if (F->flags & FIDF_SAVEACTUALHEIGHT) {
- SIZE size;
- LOGFONT lf;
- CreateFromFontSettings(&F->value, &lf);
- HFONT hFont = CreateFontIndirect(&lf);
+ int iFontSize;
+ if (F->flags & FIDF_SAVEACTUALHEIGHT) {
+ LOGFONT lf;
+ CreateFromFontSettings(&F->value, &lf);
+ HFONT hFont = CreateFontIndirect(&lf);
- HDC hdc = GetDC(hwndDlg);
- HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
- GetTextExtentPoint32(hdc, L"_W", 2, &size);
- ReleaseDC(hwndDlg, hdc);
- SelectObject(hdc, hOldFont);
- DeleteObject(hFont);
+ HDC hdc = GetDC(hwndDlg);
+ HFONT hOldFont = (HFONT)SelectObject(hdc, hFont);
- iFontSize = size.cy;
- }
- else if (F->flags & FIDF_SAVEPOINTSIZE) {
- HDC hdc = GetDC(hwndDlg);
- iFontSize = (BYTE)-MulDiv(F->value.size, 72, GetDeviceCaps(hdc, LOGPIXELSY));
- ReleaseDC(hwndDlg, hdc);
- }
- else iFontSize = F->value.size;
- fprintf(out, "%sSize=b%d\n", F->prefix, iFontSize);
+ SIZE size;
+ GetTextExtentPoint32(hdc, L"_W", 2, &size);
+ ReleaseDC(hwndDlg, hdc);
+ SelectObject(hdc, hOldFont);
+ DeleteObject(hFont);
- fprintf(out, "%sSty=b%d\n", F->prefix, F->value.style);
- fprintf(out, "%sSet=b%d\n", F->prefix, F->value.charset);
- fprintf(out, "%sCol=d%d\n", F->prefix, F->value.colour);
+ iFontSize = size.cy;
+ }
+ else if (F->flags & FIDF_SAVEPOINTSIZE) {
+ HDC hdc = GetDC(hwndDlg);
+ iFontSize = (BYTE)-MulDiv(F->value.size, 72, GetDeviceCaps(hdc, LOGPIXELSY));
+ ReleaseDC(hwndDlg, hdc);
+ }
+ else iFontSize = F->value.size;
+ fprintf(out, "%sSize=b%d\n", F->setting, iFontSize);
- if (F->flags & FIDF_NOAS)
- fprintf(out, "%sAs=w%d\n", F->prefix, 0x00FF);
+ fprintf(out, "%sSty=b%d\n", F->setting, F->value.style);
+ fprintf(out, "%sSet=b%d\n", F->setting, F->value.charset);
+ fprintf(out, "%sCol=d%d\n", F->setting, F->value.colour);
- fprintf(out, "%sFlags=w%d\n", F->prefix, F->flags);
- }
+ if (F->flags & FIDF_NOAS)
+ fprintf(out, "%sAs=w%d\n", F->setting, 0x00FF);
- header[0] = 0;
- for (auto &C : clist) {
- mir_snprintf(buff, "\n[%s]", C->dbSettingsGroup);
- if (mir_strcmp(buff, header) != 0) {
- strncpy_s(header, buff, _TRUNCATE);
- WriteLine(out, buff);
+ fprintf(out, "%sFlags=w%d\n", F->setting, F->flags);
+ continue;
}
- fprintf(out, "%s=d%d\n", C->setting, (DWORD)C->value);
- }
- header[0] = 0;
- for (auto &E : elist) {
- mir_snprintf(buff, "\n[%s]", E->dbSettingsGroup);
- if (mir_strcmp(buff, header) != 0) {
- strncpy_s(header, buff, _TRUNCATE);
- WriteLine(out, buff);
+ ColourInternal *C = (ColourInternal*)it;
+ if (clist.indexOf(C) != -1) {
+ fprintf(out, "%s=d%d\n", C->setting, (DWORD)C->value);
+ continue;
}
+
+ EffectInternal *E = (EffectInternal*)it;
fprintf(out, "%sEffect=b%d\n", E->setting, E->value.effectIndex);
fprintf(out, "%sEffectCol1=d%d\n", E->setting, E->value.baseColour);
fprintf(out, "%sEffectCol2=d%d\n", E->setting, E->value.secondaryColour);
@@ -496,9 +498,9 @@ static void sttSaveFontData(HWND hwndDlg, FontInternal &F)
char str[128];
if (F.flags & FIDF_APPENDNAME)
- mir_snprintf(str, "%sName", F.prefix);
+ mir_snprintf(str, "%sName", F.setting);
else
- strncpy_s(str, F.prefix, _TRUNCATE);
+ strncpy_s(str, F.setting, _TRUNCATE);
if (db_set_ws(0, F.dbSettingsGroup, str, F.value.szFace)) {
char buff[1024];
@@ -506,7 +508,7 @@ static void sttSaveFontData(HWND hwndDlg, FontInternal &F)
db_set_s(0, F.dbSettingsGroup, str, buff);
}
- mir_snprintf(str, "%sSize", F.prefix);
+ mir_snprintf(str, "%sSize", F.setting);
if (F.flags & FIDF_SAVEACTUALHEIGHT) {
SIZE size;
CreateFromFontSettings(&F.value, &lf);
@@ -527,17 +529,17 @@ static void sttSaveFontData(HWND hwndDlg, FontInternal &F)
}
else db_set_b(0, F.dbSettingsGroup, str, F.value.size);
- mir_snprintf(str, "%sSty", F.prefix);
+ mir_snprintf(str, "%sSty", F.setting);
db_set_b(0, F.dbSettingsGroup, str, F.value.style);
- mir_snprintf(str, "%sSet", F.prefix);
+ mir_snprintf(str, "%sSet", F.setting);
db_set_b(0, F.dbSettingsGroup, str, F.value.charset);
- mir_snprintf(str, "%sCol", F.prefix);
+ mir_snprintf(str, "%sCol", F.setting);
db_set_dw(0, F.dbSettingsGroup, str, F.value.colour);
if (F.flags & FIDF_NOAS) {
- mir_snprintf(str, "%sAs", F.prefix);
+ mir_snprintf(str, "%sAs", F.setting);
db_set_w(0, F.dbSettingsGroup, str, (WORD)0x00FF);
}
- mir_snprintf(str, "%sFlags", F.prefix);
+ mir_snprintf(str, "%sFlags", F.setting);
db_set_w(0, F.dbSettingsGroup, str, (WORD)F.flags);
}
@@ -1196,10 +1198,10 @@ int OptInit(WPARAM wParam, LPARAM)
/////////////////////////////////////////////////////////////////////////////////////////
-static FontInternal* sttFindFont(OBJLIST<FontInternal> &fonts, char *module, char *prefix)
+static FontInternal* sttFindFont(OBJLIST<FontInternal> &fonts, char *module, char *setting)
{
for (auto &F : fonts)
- if (!mir_strcmp(F->dbSettingsGroup, module) && !mir_strcmp(F->prefix, prefix))
+ if (!mir_strcmp(F->dbSettingsGroup, module) && !mir_strcmp(F->setting, setting))
return F;
return nullptr;