summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-10-13 09:45:46 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-10-13 09:45:46 +0300
commitdd0a8798f32bf192ed703c6c512d4a76c4d407bc (patch)
tree7418ccee69418a05aa1896179d2162cc297d1b01 /src/ui
parente884330ef73b2f557486a898a67a716f29887170 (diff)
Added preference for font smoothing
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/text.c30
-rw-r--r--src/ui/util.c2
2 files changed, 18 insertions, 14 deletions
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
557void deinit_Text(iText *d) { 566void 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
616static SDL_Palette *glyphPalette_(void) {
617 return prefs_App()->fontSmoothing ? activeText_->grayscale : activeText_->blackAndWhite;
618}
619
606static SDL_Surface *rasterizeGlyph_Font_(const iFont *d, uint32_t glyphIndex, float xShift) { 620static 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
894static 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
905static void finishRun_AttributedText_(iAttributedText *d, iAttributedRun *run, int endAt) { 907static 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);