aboutsummaryrefslogtreecommitdiff
path: root/box-drawing.c (unfollow)
Commit message (Collapse)AuthorLines
2025-12-26box-drawing: fenv.h: remove, not needed anymoreDaniel Eklöf-1/+0
2025-02-05box-drawings: handle architecture with soft-floatThomas Bonnefille-3/+1
Currently, architecture using soft-floats doesn't support instructions FE_INVALID, FE_DIVBYZERO, FE_OVERFLOW and FE_UNDERFLOW and so building on those architectures results with a build error. As the sqrt math function should set errno to EDOM if an error occurs, fetestexcept shouldn't be mandatory. This commit removes the float environment error handling. Signed-off-by: Thomas Bonnefille <thomas.bonnefille@bootlin.com>
2024-12-08box-drawings: implement octantsDaniel Eklöf-10/+440
2024-02-06Don't use fancy Unicode quotes, stick to ASCIIDaniel Eklöf-1/+1
2023-10-10term: cache font baselineDaniel Eklöf-1/+1
No need to redo the calculation for every single cell we render, every frame...
2023-07-25render: apply new baseline calculation everywhereDaniel Eklöf-1/+1
* URL jump labels * Scrollback position indicator * Line/box drawings characters Closes #1430
2022-04-03Use circles for rendering light arc box-drawing characters.L3MON4D3-114/+214
Ellipses can look weird when the font is narrow. Closes #988
2022-02-05fcft: adapt to API changes in fcft-3.xDaniel Eklöf-16/+16
Fcft no longer uses wchar_t, but plain uint32_t to represent codepoints. Since we do a fair amount of string operations in foot, it still makes sense to use something that actually _is_ a string (or character), rather than an array of uint32_t. For this reason, we switch out all wchar_t usage in foot to char32_t. We also verify, at compile-time, that char32_t used UTF-32 (which is what fcft expects). Unfortunately, there are no string functions for char32_t. To avoid having to re-implement all wcs*() functions, we add a small wrapper layer of c32*() functions. These wrapper functions take char32_t arguments, but then simply call the corresponding wcs*() function. For this to work, wcs*() must _also_ be UTF-32 compatible. We can check for the presence of the __STDC_ISO_10646__ macro. If set, wchar_t is at least 4 bytes and its internal representation is UTF-32. FreeBSD does *not* define this macro, because its internal wchar_t representation depends on the current locale. It _does_ use UTF-32 _if_ the current locale is UTF-8. Since foot enforces UTF-8, we simply need to check if __FreeBSD__ is defined. Other fcft API changes: * fcft_glyph_rasterize() -> fcft_codepoint_rasterize() * font.space_advance has been removed * ‘tags’ have been removed from fcft_grapheme_rasterize() * ‘fcft_log_init()’ removed * ‘fcft_init()’ and ‘fcft_fini()’ must be explicitly called
2022-02-04box-drawing: LIGHT ARC: check for sqrt() failuresDaniel Eklöf-0/+12
Closes #914
2021-09-24term: only scale using DPI if *all* monitors have a scaling factor or oneDaniel Eklöf-2/+2
With dpi-aware=auto (the default), scale fonts using DPI *only* if *all* available monitors have a scaling factor of one. The idea is this: if a user, with multiple monitors, have enabled scaling on *at least* one monitor, he/she has most likely done so to match the size of his/hers other monitors. For example, if the user has one monitor with a scaling factor of one, and another one with a scaling factor of two, he/she expects things to be twice as large on the second monitor. If we (foot) scale using DPI on the first monitor, and using the scaling factor on the second monitor, foot will *not* look twice as big on the second monitor (this was the old behavior of dpi-aware=auto). Part of #714
2021-09-19box-drawing: repair debug logsDaniel Eklöf-4/+3
2021-09-14box-drawing: braille: prefer increasing spacing over dot widthDaniel Eklöf-17/+20
Too large dots make them harder to distinguish, when the spacing between them is small. Prefer increasing the spacing, instead of increasing the dot size. This looks better at small font sizes in particular.
2021-09-12box-drawing: NOINLINE brailleDaniel Eklöf-1/+1
2021-09-12box-drawing: add braille charactersDaniel Eklöf-0/+88
Render braille ourselves, instead of using font glyphs. Decoding a braille character is easy enough; there are 256 codepoints, represented by an 8-bit integer (i.e. subtract the Unicode codepoint offset, 0x2800, and you’re left with an integer in the range 0-255). Each bit corresponds to a dot. The first 6 bits represent the upper 6 dots, while the two last bits represent the fourth (and last) row of dots. The hard part is sizing the dots and the spacing between them. The aim is to have the spacing between the dots be the same size as the dots themselves, and to have the margins on each side be half the size of the dots. In a perfectly sized cell, this means two braille characters next to each other will be evenly spaced. This is however almost never the case. The layout logic currently: * Set dot size to either the width / 4, or height / 8, depending on which one is smallest. * Horizontal spacing is initialized to the width / 4 * Vertical spacing is initialized to the height / 8 * Horizontal margins are initialized to the horizontal spacing / 2 * Vertical margins are initialized to the vertical spacing / 2. Next, we calculate the number of “remaining” pixels. That is, if we add the left margin, two dots and the spacing between, how many pixels are left on the horizontal axis? These pixels are distributed in the following order (we “stop” as soon as we run out of pixels): * If the dot size is 0 (happens for very small font sizes), increase it to 1. * If the margins are 0, increase them to 1. * If we have enough pixels (need at 2 horizontal and 4 vertical), increase the dot size. * Increase spacing. * Increase margins. Closes #702
2021-08-13pt-or-px: heed the dpi-aware settingDaniel Eklöf-28/+34
Before this patch, pt-or-px values, like letter-spacing, were *always* scaled using the current DPI value. This is wrong; if the fonts are scaled using the output’s scaling factor, then so should all other point values. This also fixes an issue where e.g. letter-spacing would use one DPI value at startup, but then when increasing/decreasing or resetting the font size, would be re-calculated using a different DPI value, leading to completely different spacing. This happened when there were multiple monitors, with different DPI values, and foot guessed the initial DPI value wrong. Normally, foot would correct itself as soon as the window was mapped, and the “correct” DPI value known. But if the fonts were scaled using the scaling factor, it was possible that the font reload never happened. This patch also updates the thickness calculation (for LIGHT and HEAVY box drawing characters) to use the scaling factor when appropriate. Closes #680
2021-08-06box-drawing: fix compiler warningDaniel Eklöf-1/+1
../../box-drawing.c: In function 'box_drawing': ../../box-drawing.c:2774:13: error: 'y1' may be used uninitialized in this function [-Werror=maybe-uninitialized] 2774 | int y0, y1; | ^~ ../../box-drawing.c:2774:9: error: 'y0' may be used uninitialized in this function [-Werror=maybe-uninitialized] 2774 | int y0, y1; | ^~
2021-08-06box-drawing: re-align sextants and wedgesDaniel Eklöf-47/+62
Improve the visual quality of sextants (and wedges) when the cell height isn’t a multiple of three.
2021-08-05box-drawing: don’t inline functions called for multiple codepointsDaniel Eklöf-5/+5
In several cases, this expanded to multiple calls, and when inlined, resulted in much larger code size.
2021-08-05box-drawing: wedges: pre-load x_halfs[] and y_thirds[]Daniel Eklöf-64/+71
This reduces the number of loads in the rest of the function.
2021-08-05box-drawing: wedges: avoid floating point mathDaniel Eklöf-68/+66
Re-use the pre-calculated offsets used by the sextants. This is the correct thing to do since wedges *should* align with sextants.
2021-08-05box-drawing: pre-calculate sextant x,y offsetsDaniel Eklöf-6/+19
We’re using floating point math, as a way to ensure that sextant primitives overlap, rather than leaving empty spaces, or being uneven, when the cell width/height isn’t divisible with 2 (width) or 3 (height). This gets rid of all floating point math from the sextant drawing functions.
2021-08-05box-drawing: deal with quads in the same as sextantsDaniel Eklöf-79/+42
That is, encode which “pieces” make up each quad in a static array, and use a single function to draw all quads using the four primitives “upper left/right, lower left/right”.
2021-08-05box-drawing: don’t inline horizontal-one-eighth-block-NDaniel Eklöf-1/+1
2021-08-05box-drawing: don’t inline light diagionalDaniel Eklöf-2/+2
2021-08-05box-drawing: wedges: fix alignment of inverted wedgesDaniel Eklöf-33/+109
We render the inverted wedges by first rendering a non-inverted triangle, and then inverting it with PIXMAN_OP_OUT. In cases where truncating and round():ing the triangle points have different results, the final, inverted wedge ends up being unaligned with the corresponding sixel(s). This patch fixes that by handling the pre-inverted triangles specifically. I.e. we don’t re-use the same triangle coordinates as the corresponding non-inverted triangle.
2021-08-05box-drawing: wedges: don’t group similar cases togetherDaniel Eklöf-48/+100
Since they’re not exactly alike, we still need branches within each case. Better to split them up - one case per codepoint.
2021-08-05box-drawing: add U+1FB3C-U+1FB6F, U+1FB9A and U+1FB9BDaniel Eklöf-4/+217
These are the “wedges” from the Unicode 13 “Legacy Computing” symbols. Closes #474
2021-07-14box-drawing: big-endian support when setting bits manuallyDaniel Eklöf-6/+16
2021-05-17box-drawing: pre-calculate the LIGHT and HEAVY thicknessesDaniel Eklöf-4/+16
2021-05-17box-drawing: always pass ‘buf’ as the first parameterDaniel Eklöf-6/+6
This way, the compiler doesn’t have to waste instructions on re-ordering the parameters
2021-05-17box-drawing: don’t inline _thickness()Daniel Eklöf-1/+1
It results in quite a lot of floating point instructions being emitted in almost every box drawing function we have...
2021-05-17box-drawing: use fill_boxes() instead of fill_rectangles()Daniel Eklöf-30/+20
2021-05-17box-drawing: increase brightness of solid shadesDaniel Eklöf-3/+3
2021-05-17config: add tweak.box-drawing-solid-shades=yes|noDaniel Eklöf-10/+11
When enabled, shades are rendered as solid blocks, using a darker variant of the current foreground color. When disabled, shades are instead rendered in a checker box pattern, using the foreground color unmodified. Default is enabled.
2021-05-17box-drawing: use an a8 buffer when primary font is antialiasedDaniel Eklöf-1/+3
This causes relevant box drawing characters (diagonals, arcs etc) to be antialiased as well.
2021-05-17box-drawing: change_buffer_format: abort on pixman failureDaniel Eklöf-0/+6
2021-05-17box-drawing: apply antialiasing to LIGHT ARCsDaniel Eklöf-40/+73
When drawing on an a8 buffer, apply antialiasing to LIGHT ARCs. This is done by supersampling; draw to a 4 times bigger buffer, then downsample, where each downsampled pixel is the average of the corresponding 4x4 pixel from the supersampled buffer. We also need to take supersampling into account while adjusting the row and col when pixel aligning the arcs with the regular horizontal/vertical lines. The shape of the ARCs can still be improved. Still, this is a much needed improvement over the current implementation. Closes #279
2021-05-17box-drawing: draw_pixman_shade(): named struct initializationDaniel Eklöf-1/+1
2021-05-17box-drawing: fix typo: missing ‘.’ in struct member initializationDaniel Eklöf-1/+1
2021-05-17box-drawing: shades can now be rendered either using solid color, or checker boxDaniel Eklöf-21/+51
For now, switching is done using a static variable. In the future, this could be a user option.
2021-05-17box-drawing: temporary “fix” for LIGHT ARCs with a8 buffersDaniel Eklöf-1/+22
We don’t have a method to draw the arcs using pixman yet. Work around this by replacing the a8 buffer with an a1 buffer, and render the arcs using our old, non-antialiased, way.
2021-05-17box-drawing: swap amount of shade for LIGHT and DARK shadesDaniel Eklöf-2/+2
The DARK shade is the one most dense, and thus the one that looks brightest.
2021-05-17box-drawing: draw shades as “antialiased” blocksDaniel Eklöf-18/+36
When rendering to an a8 surface, render shades using “transparent” pixman rectangles. When these glyphs are composited with a color, the resulting look is the color, but darkened.
2021-05-17box-drawing: use pixman_image_fill_boxes() for rect()Daniel Eklöf-10/+2
2021-05-17box-drawing: implement LIGHT diagonal lines using pixmanDaniel Eklöf-30/+52
Use trapezoids to rasterize the diagonal lines.
2021-05-17box-drawing: rect(): implement using pixmanDaniel Eklöf-7/+15
Use pixman_image_fill_rectangles() to render rectangles. Duh!
2021-05-17box-drawing: {h,v}line: implement using pixmanDaniel Eklöf-14/+20
Use pixman_image_fill_rectangles() to render horizontal and vertical lines. Despite the name, this *is* the appropriate function to use, since our lines *do* have a thickness, and thus *are* rectangles.
2021-05-17box-drawing: U+256C - BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL: add missing cornerDaniel Eklöf-1/+1
The inner corner, where the upper/left lines meet, were missing
2021-05-17box-drawing: include pixman image in the buffer we’re passing aroundDaniel Eklöf-2/+6
2021-05-04box-drawing: add Unicode 13 U+1FB70 - U+1FB8BDaniel Eklöf-2/+227
Part of #471
2021-01-16debug: rename assert() to xassert(), to avoid clashing with <assert.h>Craig Barnes-8/+8
2021-01-15box-drawing: use enum constants in draw_sextant() instead of #defineCraig Barnes-6/+8
Both are functionally equivalent here, but the former is also properly scoped, can be naturally indented and has a less repetitive syntax.
2021-01-12box-drawing: line thickness now depends on both DPI and cell sizeDaniel Eklöf-11/+21
Cell size is defined as the length of the diagonal of the cell.
2021-01-12box-drawing: LIGHT ARC: ensure row+col are within rangeDaniel Eklöf-8/+12
2021-01-12box-drawing: {h,v}line() + rect(): ensure *end* row/col is >= 0Daniel Eklöf-3/+3
2021-01-11box-drawing: x/y offsets: use pre-calculated offset values from term structDaniel Eklöf-12/+2
2021-01-11config: line-height, letter-spacing: values are in pt by default, but we allow pxDaniel Eklöf-2/+12
If the value is specified without a unit, then the value is assumed to be in points, subject to DPI scaling. The value can optionally have a ‘px’ suffix, in which case the value is treated as a raw pixel count.
2021-01-11box-drawing: compensate for non-zero {horizontal,vertical}-letter-offsetsDaniel Eklöf-2/+3
Box drawing characters should always cover the entire cell. No more, no less.
2021-01-03Use wrappers from macros.h instead of bare GCC attributes/pragmasCraig Barnes-7/+2
2021-01-02box-drawing: drop ‘pragma GCC optimize(“Os”)’Daniel Eklöf-4/+0
“The optimize attribute should be used for debugging purposes only. It is not suitable in production code.” Luckily, it seems it really isn’t needed anymore; with all the other size optimizations that has been done since this was introduced, there is no longer any difference with or without this pragma.
2021-01-02box-drawing: codespell: assymetrical -> asymmetricalDaniel Eklöf-2/+2
2021-01-02box-drawing: add macros for {h,v}line_middle_mixed()Daniel Eklöf-24/+28
Mixed here refers to mixed thickness - the lines thickness doesn’t match the thickness of an abstract, orthogonal line going through the middle of the cell.
2021-01-02box-drawing: LIGHT ARC: simpler way to adjust for asymmetrical arc when mirroringDaniel Eklöf-4/+31
When mirroring an arc, we need to adjust the mirrored position if the arc’s position in the cell is asymmetrical. This happens when *either* the line is odd sized, *or* the cell is. But not when both are. Thus, we can simply do a ‘thickness % 2 ^ width % 2’ when adjusting the position. Describe this in a comment.
2021-01-02box-drawing: LIGHT ARC: use min/max instead of checking range inside loopDaniel Eklöf-10/+5
2021-01-02box-drawing: LIGHT ARC: fix alignment of arcs when thickness is > 1pxDaniel Eklöf-29/+58
2021-01-01box-drawing: LIGHT ARC: test using a circle equation instead of a bezier curveDaniel Eklöf-73/+35
2021-01-01box-drawing: guard GCC pragma with #if defined(__GNUC__)Daniel Eklöf-1/+3
2021-01-01box-drawing: do not inline any of the utility functionsDaniel Eklöf-21/+21
2021-01-01box-drawing: dedicated functions to draw a full horizontal/vertical lineDaniel Eklöf-88/+60
2021-01-01box-drawing: convert {h,v}line_middle_{left,right,up,down}() macros to functionsDaniel Eklöf-53/+56
This greatly reduces the size of the foot binary
2021-01-01box-drawing: sextants: convert sextant_*() macros to functionsDaniel Eklöf-12/+41
While this doesn’t really reduce foot’s size, it is cleaner
2021-01-01box-drawing: quadrants: convert quad_*() macros to functionsDaniel Eklöf-25/+44
This reduces the size of the foot binary by ~4K; all the quad macros called ceil() and floor() twice per macro, which caused many float -> int -> float conversions in the expanded code. By using functions instead, there’s no expansion - the conversion only happens in one (well, four) places.
2021-01-01box-drawing: reduce number of function argumentsDaniel Eklöf-579/+589
We were using so many function arguments that a lot of the emitted code was just stack push and pops to pass around arguments. Bundle the buffer data, width, height, stride, and current DPI, into a single ‘buf’ argument. This greatly reduces the number of arguments to all functions.
2021-01-01box-drawing: force minsize optimizationDaniel Eklöf-0/+2
2021-01-01box-drawing: disable debug outputDaniel Eklöf-1/+1
2021-01-01box-drawing: LIGHT DIAGONALsDaniel Eklöf-6/+50
* U+2571 * U+2572 * U+2573
2021-01-01box-drawing: silence variable-may-not-be-initialized warningsDaniel Eklöf-2/+2
2021-01-01box-drawing: LIGHT/HEAVY DOUBLE/TRIPLE/QUADRUPLE VERTICALDaniel Eklöf-72/+138
Also combine the HORIZONTAL versions into a single draw function. * U+2506 * U+2507 * U+250A * U+250B * U+254E * U+254F
2021-01-01box-drawing: LIGHT/HEAVY DOUBLE/TRIPLE/QUADRUPLE HORIZONTALDaniel Eklöf-6/+130
*U+2504 *U+2505 *U+2508 *U+2509 *U+254C *U+254D
2021-01-01box-drawing: LIGHT ARC: improve symmetry when cell width is evenDaniel Eklöf-4/+24
2021-01-01box-drawing: LIGHT ARC: no need to do floating point since we’re truncatingDaniel Eklöf-4/+4
2021-01-01box-drawing: LIGHT ARC: pixel-perfectDaniel Eklöf-24/+26
At least in odd-sized cells, with a thickness of 1 pixel.
2021-01-01box-drawing: wip: LIGHT ARC: U+256d-U+2570Daniel Eklöf-6/+95
2021-01-01box-drawing: {h,v}line(): handle both start/end point being too small *and* too largeDaniel Eklöf-2/+8
2021-01-01box-drawing: thickness(): ensure thickness is *at least* 1pxDaniel Eklöf-1/+1
2021-01-01box-drawing: make sure we never walk outside the (image) bufferDaniel Eklöf-13/+14
2021-01-01box-drawing: wrap {h,v}hline() functions in macros, to shorten argument listDaniel Eklöf-94/+98
Rename the *function* {h,v}line() to _{h,v}line(), and add two new macros: hline() and vline(). This allows us to shorten the argument list by removing the ‘buf’ and ‘stride’ arguments.
2021-01-01box-drawing: SEXTANTS, U+1fb00-1fb3bDaniel Eklöf-0/+135
2021-01-01box-drawing: oops - remove accidental ‘x’Daniel Eklöf-1/+1
2021-01-01box-drawing: remove LOG_WARN from U+259x range - all codepoints have been implementedDaniel Eklöf-4/+1
2021-01-01box_drawing(): mark function as ‘cold’Daniel Eklöf-1/+1
2021-01-01box-drawing: remove __attribute__((__const__)) from thickness()Daniel Eklöf-1/+1
thickness() is a static function and thus ‘const’ is not necessary.
2021-01-01box-drawing: make ‘term’ parameter constDaniel Eklöf-1/+1
2021-01-01box-drawing: DOUBLE lines, U+2550-U+256CDaniel Eklöf-31/+418
2021-01-01box-drawing: LIGHT/MEDIUM/DARK SHADEDaniel Eklöf-3/+39
* U+2591 * U+2592 * U+2593
2021-01-01box-drawing: QUADRANTs: ensure all quads have equal width and hightDaniel Eklöf-4/+4
If the cell width/height is odd, the previous implementation would result in uneven quads.
2021-01-01box-drawing: QUADRANTsDaniel Eklöf-10/+86
* U+2596 * U+2597 * U+2598 * U+2599 * U+259A * U+259B * U+259C * U+259D * U+259E * U+259F
2021-01-01box-drawing: RIGHT HALF, UPPER ONE EIGHTH and RIGHT ONE EIGTHDaniel Eklöf-3/+21
* U+2590 * U+2594 * U+2595
2021-01-01box-drawing: use floating point math, and round(), when drawing block elementsDaniel Eklöf-15/+15
This is especially important for the LEFT xxx BLOCK characters, since cells can be quite narrow, and one eighth is not a lot...
2021-01-01box-drawing: first half of the block elements, U+2580-U+258FDaniel Eklöf-18/+126