membrane

chromalchemy 2024-11-15T16:17:35.650459Z

Does membrane have facilites for nuanced typographic rendering? Looking for things like: • font weight • italic variants • letter spacing • font stretch (vertical / horizontal) • line height • baseline shift • subcaps I’m assuming this depends on the runtime (backend) implementation. This stuff i think is table stakes in css. But I’m looking towards a java/clj implementation to keep it all in process and maybe enable more data composition and direct manipulation/animated workflow? Probably to render to an image for inclusion in web design. Any thoughts? Embed css-styled html inside a java/membrane canvas?

phronmophobic 2024-11-15T18:10:59.182109Z

> But I’m looking towards a java/clj implementation to keep it all in process and maybe enable more data composition and direct manipulation/animated workflow? Probably to render to an image for inclusion in web design. Any thoughts? Embed css-styled html inside a java/membrane canvas? There's a couple options. • If you render with skia using membrane.skia.paragraph, you can draw directly to an image with membrane.skia/save-image. This is probably the best option. • Java2d does have some stuff for rendering formatted text. It's been a while since I've looked at it. I remember the rendering not looking as good, but it might depend on the styles and fonts. You can also render that directly to an image. • Skia also has an SVG view, membrane.skia/svg. I think that should work with CSS, but haven't tried. There are other more complicated setups depending on your needs.

chromalchemy 2024-11-15T18:53:59.856029Z

Yeah I remember java2d and even java-fx having some suboptimal font rendering and aliasing issues.. Might check it out again. But i assume skia has the best graphical primitives. SVG, interesting, did think of that for typography but it actually makes more sense of designy api.

chromalchemy 2024-11-15T16:25:23.727199Z

What is the state of general typographic layout? (paragraphs, text flow, etc?). I know this is a deep rabbit hole..

phronmophobic 2024-11-15T16:51:05.050549Z

You can see https://phronmophobic.github.io/membrane/styled-text/index.html which should cover most use cases. This implementation is skia only, but my hope is to create a standard API with a few small changes that can be implemented by all of the backends.

phronmophobic 2024-11-16T13:13:37.215359Z

Yes, those names come from skia, https://github.com/google/skia/blob/f8ec973447335269111891765446b1695b5acd22/include/core/SkFontStyle.h#L32. Skia is the graphics library that chrome uses to render their UI and all of the HTML.

chromalchemy 2024-11-15T20:35:26.135059Z

Nice 🔥I think that covers everything but font-stretch. I will try it out!

phronmophobic 2024-11-15T21:36:49.438069Z

what is font-stretch?

chromalchemy 2024-11-15T21:52:49.369029Z

chromalchemy 2024-11-15T21:53:24.681679Z

Not sure if this is a native font feature. But something I use a lot in photoshop.

phronmophobic 2024-11-15T22:29:48.017619Z

oh, it looks like it's actually supported, but not documented

phronmophobic 2024-11-15T22:31:11.714879Z

Actually, I think it is documented. I think font-stretch is actually the same as setting the :font-style/width.

phronmophobic 2024-11-15T22:32:40.395639Z

> Note: The font-stretch property https://drafts.csswg.org/css-fonts/#font-stretch-desc`font-width` in the specifications. At least if you're talking about the same option as the css font-stretch property. That's one of the benefits of using skia is that you should theoretically be able to render anything that you find in the browser.

chromalchemy 2024-11-16T03:32:24.278289Z

Yes. I thought at first the :condensed, etc parameters were referring to letter spacing. But indeed in css parlance, it refers to stretching the glyphs! I was thinking more about stretching arbitrary percentages. And that is supported by css, and also seems require a compatible typeface.

chromalchemy 2024-11-16T04:08:44.746859Z

I’m confused by the reference to css names. Are those names you are mirroring in your api? > Skia doesn’t have built-in properties like font-stretch or font-width, but you can achieve similar effects programmatically: > • Use setScaleX for horizontal scaling (wider or narrower text).

phronmophobic 2024-11-15T16:51:54.921069Z

I’ve also been exposing more and more of the layout information which will be part of the next release.

phronmophobic 2024-11-15T16:53:21.982509Z

I’m away from keyboard, but I’ll be back in a bit.

phronmophobic 2024-11-15T18:12:21.899279Z

The API is still open to feedback. One thing I'll probably change for the standardized APIs is to use fewer namespaced keywords. I find them to be cumbersome in the membrane.skia.paragraph API without much benefit.

chromalchemy 2024-11-15T20:30:10.831259Z

I’m sympathetic to this.

chromalchemy 2024-11-15T20:31:48.752449Z

While I’m more appreciative of clojure’s focus on data provenance in the large (vs type systems). I find namespaced keywords add lot of noise to local logic and can make it less fun to read and reason about code.

👍 1
💯 1
phronmophobic 2024-11-15T22:35:57.920369Z

Yup. I'll probably update the API to also allow unqualified keywords at some point. I do try really hard to maintain backwards compatibility so I'll probably spend a bit more time thinking about the how to grow the API in a way that improves usability and maintains backwards compatibility.