diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-13 09:45:46 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-10-13 09:45:46 +0300 |
commit | dd0a8798f32bf192ed703c6c512d4a76c4d407bc (patch) | |
tree | 7418ccee69418a05aa1896179d2162cc297d1b01 /src | |
parent | e884330ef73b2f557486a898a67a716f29887170 (diff) |
Added preference for font smoothing
Diffstat (limited to 'src')
-rw-r--r-- | src/app.c | 16 | ||||
-rw-r--r-- | src/prefs.c | 1 | ||||
-rw-r--r-- | src/prefs.h | 1 | ||||
-rw-r--r-- | src/ui/text.c | 30 | ||||
-rw-r--r-- | src/ui/util.c | 2 |
5 files changed, 35 insertions, 15 deletions
@@ -233,6 +233,7 @@ static iString *serializePrefs_App_(const iApp *d) { | |||
233 | appendFormat_String(str, "returnkey.set arg:%d\n", d->prefs.returnKey); | 233 | appendFormat_String(str, "returnkey.set arg:%d\n", d->prefs.returnKey); |
234 | /* TODO: Set up an array of booleans in Prefs and do these in a loop. */ | 234 | /* TODO: Set up an array of booleans in Prefs and do these in a loop. */ |
235 | appendFormat_String(str, "prefs.animate.changed arg:%d\n", d->prefs.uiAnimations); | 235 | appendFormat_String(str, "prefs.animate.changed arg:%d\n", d->prefs.uiAnimations); |
236 | appendFormat_String(str, "prefs.font.smooth.changed arg:%d\n", d->prefs.fontSmoothing); | ||
236 | appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini); | 237 | appendFormat_String(str, "prefs.mono.gemini.changed arg:%d\n", d->prefs.monospaceGemini); |
237 | appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher); | 238 | appendFormat_String(str, "prefs.mono.gopher.changed arg:%d\n", d->prefs.monospaceGopher); |
238 | appendFormat_String(str, "prefs.boldlink.dark.changed arg:%d\n", d->prefs.boldLinkDark); | 239 | appendFormat_String(str, "prefs.boldlink.dark.changed arg:%d\n", d->prefs.boldLinkDark); |
@@ -2334,7 +2335,19 @@ iBool handleCommand_App(const char *cmd) { | |||
2334 | } | 2335 | } |
2335 | else if (equal_Command(cmd, "quoteicon.set")) { | 2336 | else if (equal_Command(cmd, "quoteicon.set")) { |
2336 | d->prefs.quoteIcon = arg_Command(cmd) != 0; | 2337 | d->prefs.quoteIcon = arg_Command(cmd) != 0; |
2337 | postCommand_App("document.layout.changed"); | 2338 | postCommand_App("document.layout.changed redo:1"); |
2339 | return iTrue; | ||
2340 | } | ||
2341 | else if (equal_Command(cmd, "prefs.font.smooth.changed")) { | ||
2342 | if (!isFrozen) { | ||
2343 | setFreezeDraw_MainWindow(get_MainWindow(), iTrue); | ||
2344 | } | ||
2345 | d->prefs.fontSmoothing = arg_Command(cmd) != 0; | ||
2346 | if (!isFrozen) { | ||
2347 | resetFonts_Text(text_Window(get_MainWindow())); /* clear the glyph cache */ | ||
2348 | postCommand_App("font.changed"); | ||
2349 | postCommand_App("window.unfreeze"); | ||
2350 | } | ||
2338 | return iTrue; | 2351 | return iTrue; |
2339 | } | 2352 | } |
2340 | else if (equal_Command(cmd, "prefs.mono.gemini.changed") || | 2353 | else if (equal_Command(cmd, "prefs.mono.gemini.changed") || |
@@ -2750,6 +2763,7 @@ iBool handleCommand_App(const char *cmd) { | |||
2750 | setFlags_Widget(findChild_Widget(dlg, "prefs.boldlink.light"), | 2763 | setFlags_Widget(findChild_Widget(dlg, "prefs.boldlink.light"), |
2751 | selected_WidgetFlag, | 2764 | selected_WidgetFlag, |
2752 | d->prefs.boldLinkLight); | 2765 | d->prefs.boldLinkLight); |
2766 | setToggle_Widget(findChild_Widget(dlg, "prefs.font.smooth"), d->prefs.fontSmoothing); | ||
2753 | setFlags_Widget( | 2767 | setFlags_Widget( |
2754 | findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)), | 2768 | findChild_Widget(dlg, format_CStr("prefs.linewidth.%d", d->prefs.lineWidth)), |
2755 | selected_WidgetFlag, | 2769 | selected_WidgetFlag, |
diff --git a/src/prefs.c b/src/prefs.c index 65560264..f51538ac 100644 --- a/src/prefs.c +++ b/src/prefs.c | |||
@@ -60,6 +60,7 @@ void init_Prefs(iPrefs *d) { | |||
60 | setCStr_String(&d->strings[bodyFont_PrefsString], "default"); | 60 | setCStr_String(&d->strings[bodyFont_PrefsString], "default"); |
61 | setCStr_String(&d->strings[monospaceFont_PrefsString], "iosevka"); | 61 | setCStr_String(&d->strings[monospaceFont_PrefsString], "iosevka"); |
62 | setCStr_String(&d->strings[monospaceDocumentFont_PrefsString], "iosevka-body"); | 62 | setCStr_String(&d->strings[monospaceDocumentFont_PrefsString], "iosevka-body"); |
63 | d->fontSmoothing = iTrue; | ||
63 | d->monospaceGemini = iFalse; | 64 | d->monospaceGemini = iFalse; |
64 | d->monospaceGopher = iFalse; | 65 | d->monospaceGopher = iFalse; |
65 | d->boldLinkDark = iTrue; | 66 | d->boldLinkDark = iTrue; |
diff --git a/src/prefs.h b/src/prefs.h index dc233cdc..d1131aae 100644 --- a/src/prefs.h +++ b/src/prefs.h | |||
@@ -87,6 +87,7 @@ struct Impl_Prefs { | |||
87 | int maxCacheSize; /* MB */ | 87 | int maxCacheSize; /* MB */ |
88 | int maxMemorySize; /* MB */ | 88 | int maxMemorySize; /* MB */ |
89 | /* Style */ | 89 | /* Style */ |
90 | iBool fontSmoothing; | ||
90 | iBool monospaceGemini; | 91 | iBool monospaceGemini; |
91 | iBool monospaceGopher; | 92 | iBool monospaceGopher; |
92 | iBool boldLinkDark; | 93 | iBool boldLinkDark; |
diff --git a/src/ui/text.c b/src/ui/text.c index 3d2cdf5d..fd865fbd 100644 --- a/src/ui/text.c +++ b/src/ui/text.c | |||
@@ -260,6 +260,7 @@ struct Impl_Text { | |||
260 | int cacheBottom; | 260 | int cacheBottom; |
261 | iArray cacheRows; | 261 | iArray cacheRows; |
262 | SDL_Palette * grayscale; | 262 | SDL_Palette * grayscale; |
263 | SDL_Palette * blackAndWhite; /* unsmoothed glyph palette */ | ||
263 | iRegExp * ansiEscape; | 264 | iRegExp * ansiEscape; |
264 | }; | 265 | }; |
265 | 266 | ||
@@ -549,12 +550,21 @@ void init_Text(iText *d, SDL_Renderer *render) { | |||
549 | d->grayscale = SDL_AllocPalette(256); | 550 | d->grayscale = SDL_AllocPalette(256); |
550 | SDL_SetPaletteColors(d->grayscale, colors, 0, 256); | 551 | SDL_SetPaletteColors(d->grayscale, colors, 0, 256); |
551 | } | 552 | } |
553 | /* Black-and-white palette for unsmoothed glyphs. */ { | ||
554 | SDL_Color colors[256]; | ||
555 | for (int i = 0; i < 256; ++i) { | ||
556 | colors[i] = (SDL_Color){ 255, 255, 255, i < 100 ? 0 : 255 }; | ||
557 | } | ||
558 | d->blackAndWhite = SDL_AllocPalette(256); | ||
559 | SDL_SetPaletteColors(d->blackAndWhite, colors, 0, 256); | ||
560 | } | ||
552 | initCache_Text_(d); | 561 | initCache_Text_(d); |
553 | initFonts_Text_(d); | 562 | initFonts_Text_(d); |
554 | activeText_ = oldActive; | 563 | activeText_ = oldActive; |
555 | } | 564 | } |
556 | 565 | ||
557 | void deinit_Text(iText *d) { | 566 | void deinit_Text(iText *d) { |
567 | SDL_FreePalette(d->blackAndWhite); | ||
558 | SDL_FreePalette(d->grayscale); | 568 | SDL_FreePalette(d->grayscale); |
559 | deinitFonts_Text_(d); | 569 | deinitFonts_Text_(d); |
560 | deinitCache_Text_(d); | 570 | deinitCache_Text_(d); |
@@ -603,6 +613,10 @@ void resetFonts_Text(iText *d) { | |||
603 | initFonts_Text_(d); | 613 | initFonts_Text_(d); |
604 | } | 614 | } |
605 | 615 | ||
616 | static SDL_Palette *glyphPalette_(void) { | ||
617 | return prefs_App()->fontSmoothing ? activeText_->grayscale : activeText_->blackAndWhite; | ||
618 | } | ||
619 | |||
606 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, float xShift) { | 620 | static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, float xShift) { |
607 | int w, h; | 621 | int w, h; |
608 | uint8_t *bmp = rasterizeGlyph_FontFile(d->fontFile, d->xScale, d->yScale, xShift, glyphIndex, | 622 | uint8_t *bmp = rasterizeGlyph_FontFile(d->fontFile, d->xScale, d->yScale, xShift, glyphIndex, |
@@ -610,7 +624,7 @@ static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, fl | |||
610 | SDL_Surface *surface8 = | 624 | SDL_Surface *surface8 = |
611 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); | 625 | SDL_CreateRGBSurfaceWithFormatFrom(bmp, w, h, 8, w, SDL_PIXELFORMAT_INDEX8); |
612 | SDL_SetSurfaceBlendMode(surface8, SDL_BLENDMODE_NONE); | 626 | SDL_SetSurfaceBlendMode(surface8, SDL_BLENDMODE_NONE); |
613 | SDL_SetSurfacePalette(surface8, activeText_->grayscale); | 627 | SDL_SetSurfacePalette(surface8, glyphPalette_()); |
614 | #if LAGRANGE_RASTER_DEPTH != 8 | 628 | #if LAGRANGE_RASTER_DEPTH != 8 |
615 | /* Convert to the cache format. */ | 629 | /* Convert to the cache format. */ |
616 | SDL_Surface *surf = SDL_ConvertSurfaceFormat(surface8, LAGRANGE_RASTER_FORMAT, 0); | 630 | SDL_Surface *surf = SDL_ConvertSurfaceFormat(surface8, LAGRANGE_RASTER_FORMAT, 0); |
@@ -890,18 +904,6 @@ static iRangecc sourceRange_AttributedText_(const iAttributedText *d, iRangei lo | |||
890 | return range; | 904 | return range; |
891 | } | 905 | } |
892 | 906 | ||
893 | #if 0 | ||
894 | static iBool isAllSpace_AttributedText_(const iAttributedText *d, iRangei range) { | ||
895 | const iChar *logicalText = constData_Array(&d->logical); | ||
896 | for (size_t i = range.start; i < range.end; i++) { | ||
897 | if (logicalText[i] != 0x20) { | ||
898 | return iFalse; | ||
899 | } | ||
900 | } | ||
901 | return iTrue; | ||
902 | } | ||
903 | #endif | ||
904 | |||
905 | static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, int endAt) { | 907 | static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, int endAt) { |
906 | iAttributedRun finishedRun = *run; | 908 | iAttributedRun finishedRun = *run; |
907 | iAssert(endAt >= 0 && endAt <= size_Array(&d->logical)); | 909 | iAssert(endAt >= 0 && endAt <= size_Array(&d->logical)); |
@@ -1184,7 +1186,7 @@ static void cacheGlyphs_Font_(iFont *d, const iArray *glyphIndices) { | |||
1184 | LAGRANGE_RASTER_DEPTH, | 1186 | LAGRANGE_RASTER_DEPTH, |
1185 | LAGRANGE_RASTER_FORMAT); | 1187 | LAGRANGE_RASTER_FORMAT); |
1186 | SDL_SetSurfaceBlendMode(buf, SDL_BLENDMODE_NONE); | 1188 | SDL_SetSurfaceBlendMode(buf, SDL_BLENDMODE_NONE); |
1187 | SDL_SetSurfacePalette(buf, activeText_->grayscale); | 1189 | SDL_SetSurfacePalette(buf, glyphPalette_()); |
1188 | } | 1190 | } |
1189 | SDL_Surface *surfaces[2] = { | 1191 | SDL_Surface *surfaces[2] = { |
1190 | !isRasterized_Glyph_(glyph, 0) ? | 1192 | !isRasterized_Glyph_(glyph, 0) ? |
diff --git a/src/ui/util.c b/src/ui/util.c index 3240b416..653102cb 100644 --- a/src/ui/util.c +++ b/src/ui/util.c | |||
@@ -2568,6 +2568,8 @@ iWidget *makePreferences_Widget(void) { | |||
2568 | addDialogPadding_(headings, values); | 2568 | addDialogPadding_(headings, values); |
2569 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.font.ui}"))); | 2569 | addChild_Widget(headings, iClob(makeHeading_Widget("${prefs.font.ui}"))); |
2570 | addFontButtons_(values, "ui"); | 2570 | addFontButtons_(values, "ui"); |
2571 | addDialogPadding_(headings, values); | ||
2572 | addDialogToggle_(headings, values, "${prefs.font.smooth}", "prefs.font.smooth"); | ||
2571 | // addDialogPadding_(headings, values); | 2573 | // addDialogPadding_(headings, values); |
2572 | // /* Custom font. */ { | 2574 | // /* Custom font. */ { |
2573 | // iInputWidget *customFont = new_InputWidget(0); | 2575 | // iInputWidget *customFont = new_InputWidget(0); |