Minimise width of the multi-line text in Flutter - text

I have a variable-width container (screen width) and fixed left and right margins. Remaining area gives me a constraint for maximum text width, where I'm placing text of variable content (multiple languages). I want text to fit into that width without truncation, wrapping if needed. Text is relatively short - it may fit into single line, likely to fit into 2 lines and will fit into 3 lines for sure.
I want to avoid cases like (2) - where text wraps into long and a short line. It does not look nice. Instead I would like it to wrap more evenly, like in case (3).
For the demo purposes I've hardcoded hand-picked margins, but I want solution to work automatically for any text content and any container width.
Is it achievable using built-in Flutter widgets, or I need to implement something custom, similar to https://pub.dartlang.org/packages/auto_size_text?

Related

Is there any way to draw large characters using ncursesw?

I want to create a main page for a program I'm trying to write and basically, I want to print the title at the center with a large font and menu and the rest after that. What I'm looking for is any character set in ncursesw or just anything which will help me draw large characters for title more precisely
For this (in ncurses), I tried A_REVERSE attribute and printed the respective places white, something like this
Large text
But other letters like z, g and t are hard to draw and they don't look good either.

Allign shapes and text in SVG for PDF generation

I would like to generate some diagram style graphics using SVG and use text in the diagrams. My problem is, how to know the size of the text in advance to be able to adjust the rest of the layout accordingly. To make this explicit: I'm not talking about SVG in a browser. I would like to work with fixed units and generate PDF for printing for example. So if I use a 12pt font, it should also be printed as 12pt font.
To have a more concrete example: Lets assume I have the three strings "bla", "blablub" and "blubblablub". I would like to print them in a given 12pt font, determine the string size and enclosing boxes and draw the biggest sized box around all of them. The idea is to have equally sized boxed around all, based on the longest text.
Could somebody give me a hint how to do that or why it is not possible? Searching for this topic, I only get some JavaScript tricks in the browser, which usually involves rendering the text and then re-rendering everything again.

Partial ligature selection with DirectWrite

Using HitTestTextPosition style API from IDWriteTextLayout I did not managed to handle properly text positions inside "ti", "ffi" or other ligatures with fonts like Calibri. It always returns position after or before ligature not inside like t|i or f|f|i.
What is the recommended way to do a caret movement inside ligatures with DirectWrite API?
There... is no "inside" position if you have GSUB replacements turned on?
Opentype GSUB ligatures are single glyph replacements for codepoint sequences, rather than being "several glyphs, smushed together". They are literally distinct, single glyphs, with single bounding boxes, and a single left and right side bearing for cursor placement/alignment. If you have the text A + E and the font has a ligature replacement that turns it into Ӕ then with ligatures enabled there really are only two cursor positions in that code sequence: |Ӕ and Ӕ|. You can't place the cursor "in the middle", because there is no "middle"; it's a single, atomic, indivisible element.
The same goes for f. ligatures like ff, fi, fl, ffi, ffl, or ſt: these are single glyphs once shaped with GSUB turned on. This is in fact what's supposed to happen: having GSUB ligatures enabled means you expressly want text to be presented—for all intents and purposes—as having atomic glyphs for many-to-one substitutions, like turning the full phrase "صلى الله عليه وعلى آله وسلم‎", as well as variations of that, into the single glyph ﷺ.
If you want to work with the base codepoint sequences (so that if you have a text with f + f + i it doesn't turn that into ffi) you will need to load the font with the liga OpenType feature disabled.
The text editors I know of use the simple hack of (1) dividing the width of the glyph cluster by the number of code points within the cluster (excluding any zero width combining marks), rather than use the GDEF caret positioning information. This includes even Word, which you can tell if you look closely enough below. It's not precise, but since it's simple and close enough at ordinary reading sizes, it's what many do:
(2) I've heard that some may (but don't know which) also use the original glyph advances of the unshaped characters (pre-ligation) and scale them proportionally to the ligature cluster width.
(3) Some text editors may use the GDEF table, but I never knew of any for sure (possibly Adobe In-Design?).
The most challenging aspect of using methods 2 or 3 with IDWriteTextLayout is that accessing the corresponding IDWriteFontFace in that run requires quite the indirection because the specific IDWriteFontFace used (after resolving font family name+WWS+variable font axes) is stored in the layout but not publicly accessible via any "getter" API. The only way you can extract them is by "drawing" the glyph runs via IDWriteTextLayout::Draw into a user-defined IDWriteTextRenderer interface to record all the DWRITE_GLYPH_RUN::fontFace's. Then you could call IDWriteFontFace::GetDesignGlyphAdvances on the code points or IDWriteFontFace::TryGetFontTable to read the OpenType GDEF table (which is complex to read). It's a lot of work, and that's because...
The official PadWrite example has the same issue
IDWriteTextLayout was designed for displaying text rather than editing it. It has some functionality for hit-testing which is useful if you want to display an underlined link in a paragraph and test for it being clicked (in which case the ligature would be whole anyway within a word), or if you want to draw some decorations around some text, but it wasn't really intended for the full editing experience, which includes caret navigation. It was always intended that actual text editing engines (e.g. those used in Word, PowerPoint, OpenOffice, ...) would call the lower level API's, which they do.
The PadWrite sample I wrote is a little misleading because although it supports basic editing, that was just so you can play around with the formatting and see how things worked. It had a long way to go before it could really be an interactive editor. For one (the big one), it completely recreated the IDWriteTextLayout each edit, which is why the sample only presented a few paragraphs of text, because a full editor with several pages of text would want to incrementally update the text. I don't work on that team anymore, but I've thought of creating a DWrite helper library on GitHub to fill in some hindsight gaps, and if I ever did, I'd probably just ... use method 1 :b.

SVG tspan transform skew

I'm looking for a way to skew a tspan with transform="skewX(-45)", but it only seems to work on the parent text as a whole. The problem is a want surrounding tspans to be unaffected by the skew, only the middle one. The reason I don't want to use multiple texts is that I want the flow calculations to be done for me instead of me positioning the texts manually (so future font change doesn't throw the text flow off). I also need the following text spans to be flown with respect to the width of the slanted text span, not the original one.
Is there a way to apply transform to a tspan only or can this be done with multiple texts while preserving the text flow?
Per ccprog's comment, there are some rendering issues / complications with using transforms on <tspan>.
Here are the available attributes on <tspan>:
You might be able to fit your needs by combining rotate, dx, & dy to various effects. Some people have had luck wrapping the <text> element inside of an <a> as it does allow transform.

LaTeX \includegraphics and textline

Ok, I am beat. I tried a few things but I am unable to make this happen. I need some help now.
I want to be able to have some text and picture side by side (only one line, thus no need for wrapping or other fun. The picture is small enough to fit in a text line):
This is a text <temp.jpg placed center to the textline>
Problem is, when I use
This is a text \includegraphics{temp.jpg}
the pictures baseline is alligned with the text baseline. I want the picture (vertical) center to be aligned with the text baseline. How can I make this possible?
This is a text $\vcenter{\hbox{\includegraphics{temp.jpg}}}$
It sounds like you want \raisebox (see the raisebox section of the LaTeX wikibook), with a negative argument. Use dimensions ex (the notional height of an 'x' in the current font) or \baselineskip (the size between text baselines) as your units.
If you want to do more complicated things, such as move the graphics box down by half its height, you can, but it gets fiddly. If the graphic size isn't unpredictable, you're probably better off tuning this by hand anyway.
In my opinion, most simple answer \raisebox{-0.5\totalheight}{<your graphic here>}
This is a text \raisebox{-0.5\totalheight}{\includegraphics{temp.jpg}}
Explanation:
\raisebox moves vertically the whole text/picture given as second argument. The first argument is the vertical shift as a length. This command provides the length \totalheight which is, self-explanatory, the height of the whole text/picture that you want to raise. The factor -0.5 lowers exactly at the half of the length(as the question demands). For aesthetic adjustments just modify the factor's value.
By the way, with this method there is no need to get into math mode as in #AlexeiMalistov answer, and no need of double command \vcenter + \hbox

Resources