about summary refs log tree commit diff stats
path: root/src/layout/renderdocument.nim
Commit message (Collapse)AuthorAgeFilesLines
* sixel: support transparencybptato2024-09-241-3/+1
| | | | | | | | | | | | | | | | | | Sixel can only represent transparency for fully transparent (alpha = 0) and fully opaque (alpha = 255) pixels, i.e. we would have to do blending ourselves to do this "properly". But what do you even blend? Background color? Images? Clearly you can't do text... So instead of going down the blending route, we now just approximate the 8-bit channel with Sixel's 1-bit channel and then patch it up with dither. It does look a bit weird, but it's not *that* bad, especially compared to the previous strategy of "blend with some color which hopefully happens to be the background color" (it rarely was). Note that this requires us to handle transparent images specially in term. That is, for opaque ones, we can leave out the "clear cells affected by image" part, but for transparent ones, we must clear the entire image every time.
* sixel: use inline background for blendingbptato2024-09-241-1/+3
| | | | still not really great, because inline background is a mess too
* Refactor img/*bptato2024-09-151-1/+1
| | | | | I've moved most image logic to adapter, so it doesn't really make sense to have this subdir anymore.
* renderdocument: fix image background coloringbptato2024-09-131-13/+16
| | | | special case it in paintBackground so that it doesn't look so ugly
* utils: add twtunibptato2024-09-081-10/+5
| | | | | | | | | | | | | | | | | | | std/unicode has the following issues: * Rune is an int32, which implies overflow checking. Also, it is distinct, so you have to convert it manually to do arithmetic. * QJS libunicode and Chagashi work with uint32, interfacing with these required pointless type conversions. * fastRuneAt is a template, meaning it's pasted into every call site. Also, it decodes to UCS-4, so it generates two branches that aren't even used. Overall this lead to quite some code bloat. * fastRuneAt and lastRune have frustratingly different interfaces. Writing code to handle both cases is error prone. * On older Nim versions which we still support, std/unicode takes strings, not openArray[char]'s. Replace it with "twtuni", which includes some improved versions of the few procedures from std/unicode that we actually use.
* canvas: move to separate CGI scriptbptato2024-09-011-1/+1
| | | | | | | | | | * stream: and passFd is now client-based, and accessible for buffers * Bitmap's width & height is now int, not uint64 * no more non-network Bitmap special case in the pager for canvas I just shoehorned it into the static image model, so it still doesn't render changes after page load. But at least now it doesn't crash the browser.
* buffer, pager, config: add meta-refresh + misc fixesbptato2024-07-281-1/+1
| | | | | | | | | * buffer, pager, config: add meta-refresh value, which makes it possible to follow http-equiv=refresh META tags. * config: clean up redundant format mode parser * timeout: accept varargs for params to pass on to functions * pager: add "options" dict to JS gotoURL * twtstr: remove redundant startsWithNoCase
* layout: merge neighboring wordsbptato2024-07-281-20/+0
| | | | Great performance win on large documents.
* layout: fix incorrect absolute positioningbptato2024-07-251-11/+22
| | | | It was broken for parent boxes with indefinite sizes.
* renderdocument: fix clickable imagesbptato2024-07-121-0/+5
| | | | | | | | Paint the background with the current color, so that it gets associated with the owner styled node. (I didn't want to do this because it's slow, but otherwise image-mode gets very annoying to use.)
* renderdocument: clean up setTextbptato2024-07-061-100/+107
|
* layout: fix positioning bugbptato2024-07-021-4/+5
| | | | | top/left/right/bottom should only be used in renderdocument with position: absolute.
* renderdocument: avoid recursionbptato2024-06-301-9/+12
|
* img, loader: add image resizing, misc fixesbptato2024-06-281-0/+4
| | | | | | | | | | | | | | | * resize images with stb_image_resize * use tee for output handle redirection (redirectToFile blocks) * cache original image files * accept lseek in sandbox * misc stbi fixes For now, I just pulled in stb_image_resize v1. v2 is an extra 150K in size, not sure if it's worth the cost. (Either way, we can always switch later if needed, since the API is almost the same.) Next step: move sixel/kitty encoders to CGI, and cache their output in memory instead of the intermediate RGBA representation.
* layout: inline fixes & improvementsbptato2024-06-271-0/+3
| | | | | | | | | | | | | | | * fix text-align breaking down in the presence of floats * improve (and simplify) background color area painting This greatly simplifies inline layout by removing the additional text-align atom movement code and replacing it with a full re-layout when needed. That re-layout only occurs in (rare) cases where the text is likely to be relatively short anyway, so it's probably a win in any remotely realistic layout. This has also made it possible to at last merge the last three passes (horizontal/vertical alignment and background painting) and drop that weird synchronized tree + vector traversal.
* renderdocument: handle overlapping double width charsbptato2024-06-021-1/+6
| | | | | See attached test case; previously, this would result in a missing space in visual mode and a crash in dump mode.
* layout: clean up inline tree constructionbptato2024-06-011-5/+4
| | | | | | | Much cleaner than the previous solution. Should also be somewhat less wasteful, as we no longer constantly rebuild the same tree with new branches.
* layout: misc refactoringsbptato2024-05-291-2/+1
|
* layout: get rid of InlineBoxBuilderbptato2024-05-281-5/+5
| | | | just merge it with InlineFragment
* layout: remove BlockBoxBuidlerbptato2024-05-271-7/+6
| | | | | | | | | | Instead of allocating a separate object for each box, just re-use a single BlockBox on re-layouts. This means that now the (block-level) tree is built in its final form in the first pass. (Inline boxes remain the same as before for now.)
* css/values -> css/cssvaluesbptato2024-05-161-1/+1
| | | | for consistency
* layout: unify some code pathsbptato2024-05-091-17/+6
| | | | | | | Turn Offset, Size, etc. into arrays indexed by a DimensionType enum, and use it to unify code that only differs in the dimension it is computing for. (e.g. this lets us use the same code for flex row & column layouts.)
* color: RGBAColor -> ARGBColorbptato2024-04-261-2/+2
|
* Initial image supportbptato2024-04-251-11/+28
| | | | | | | | | | | | | | | | | * png: add missing filters, various decoder fixes * term: fix kitty response interpretation, add support for kitty image detection * buffer, pager: initial image display support Emphasis on "initial"; it only "works" with kitty output and PNG input. Also, it's excruciatingly slow, and repaints images way too often. Left undocumented intentionally it for now, until it actually becomes useful. In the meantime, adventurous users can find out themselves why: [[siteconf]] url = "https://.*" images = true
* Update code stylebptato2024-04-171-10/+10
| | | | | | * separate params with ; (semicolon) instead of , (colon) * reduce screaming snake case use * wrap long lines
* layout: remove ListItemBox, handle inline-flex correctlybptato2024-04-151-10/+0
| | | | | This allows us to unify BlockBox instantiation and block-level inner layout calls.
* renderdocument: do not layout with styledRoot == nilbptato2024-04-111-1/+4
| | | | it can happen when do_reshape is called before any parsing happens.
* layout: rework inline box area modelbptato2024-03-251-29/+10
| | | | | | | | | | | | | Specifying the background area as three LayoutUnit pairs sounds clever, but breaks down for text-align: center. * store line Y offset in LineBox - this is necessary to pass down areas we need to paint * refactor addHorizontalLine loop; remove mystery "If necessary, update ictx's width" line that used to be labeled "TODO this seems meaningless" and indeed seems meaningless now (I am prepared to deeply regret this later) * replace broken & convoluted startOffset/endOffset/size with a simple seq of offsets + sizes
* cell: update FormatFlag naming, remove useless templatesbptato2024-03-211-6/+6
|
* Move around some modulesbptato2024-03-141-1/+1
| | | | | | | | * extern -> gone, runproc absorbed by pager, others moved into io/ * display -> local/ (where else would we display?) * xhr -> html/ * move out WindowAttributes from term, so we don't depend on local from server
* strwidth, renderdocument: small refactoringbptato2024-03-031-73/+61
| | | | | | * put attrs pointer in state * simplify width() * use unsigned int as ptint to avoid UB
* term: improve pixels-per-column/line detectionbptato2024-02-251-2/+59
| | | | | | | | | Some terminal emulators (AKA vte) refuse to set ws_xpixel and ws_ypixel in the TIOCGWINSZ ioctl, so we now query for CSI 14 t as well. (Also CSI 18 t for good measure, just in case we can't ioctl for some reason.) Also added some fallback (optionally forced) config values for width, height, ppc, and ppl. (This is especially useful in dump mode.)
* Separate ANSI text decoding from main binarybptato2024-02-251-0/+437
Handling text/plain as ANSI colored text was problematic for two reasons: * You couldn't actually look at the real source of HTML pages or text files that used ANSI colors in the source. In general, I only want ANSI colors when piping something into my pager, not when viewing any random file. * More importantly, it introduced a separate rendering mode for plaintext documents, which resulted in the problem that only some buffers had DOMs. This made it impossible to add functionality that would operate on the buffer's DOM, to e.g. implement w3m's MARK_URL. Also, it locked us into the horribly inefficient line-based rendering model of entire documents. Now we solve the problem in two separate parts: * text/x-ansi is used automatically for documents received through stdin. A text/x-ansi handler ansi2html converts ANSI formatting to HTML. text/x-ansi is also used for .ans, .asc file extensions. * text/plain is a separate input mode in buffer, which places all text in a single <plaintext> tag. Crucially, this does not invoke the HTML parser; that would eat NUL characters, which we should avoid. One blind spot still remains: copiousoutput used to display ANSI colors, and now it doesn't. To solve this, users can put the x-ansioutput extension field to their mailcap entries, which behaves like x-htmloutput except it first pipes the output into ansi2html.