Ambiguous width Unicode characters are either halfwidth or fullwidth depending on the context (locale, font, surrounding characters).
How can I force NSTextView to always render ambiguous width characters as halfwidth? Is there some normalization algorithm that I should use? Ideally, there would be a configuration where I can set this.
Related
I'm developing a text renderer library which is similar to FreeType for my game. I don't know how to determine the tab width.
When I'm handling control characters, I found a problem, that is my text renderer is not only for monospace fonts but also for non-monospace fonts. I know that for monospace fonts, the width of the tab aligning can be 4 or 8 spaces, depending on the usage of the text renderer (AFAIK, most of the programming IDEs intend tabs to 4 spaces; and for creating tables, the software often intend tabs to 8 spaces). But for non-monospace fonts, which value should I use?
After watching lots of IDE's behavior of handling non-monospace fonts, I found the answer:
Use the width of space character ('\x20') as the unit of the tab width, and the tab width should be 4 spaces by default.
Also I gave a choice for the users to determine how to align characters for non-monospace fonts, one is to align characters normally as we see how other programs (such as Microsoft Word, Chrome, etc.) align non-monospace font text, the other one is to force aligning characters as monospace style by fix the width value of each characters, and the fixed width value were determined by scan all of the alphabets, digits and punctuations, and find a maximum value for it. And for full-width characters, I just let the width value x 2.
Which is the font style used in NSFont to create alignment/space between characters?
I tried doing with this code, but not able to align the characters.
NSFont *font=[NSFont fontWithName:#"TimesNewRomanPSMT" size:15.0 ];
[textview setFont: font];
Please specify the font style name which suits the above mentioned problem.
What about trying fontspace and pick the font you want.
And if you are looking to adjust the space between characters in a UILabel you can use:
#property(nonatomic) BOOL adjustsLetterSpacingToFitWidth;
Edit: Above code for ios.
I am implementing an iChat-like app, using NSTextView to display chat records. The problem is how to change the width of NSTextView automatically based on characters in it. For example, the width of NSTextView is only one character width if there's only one character in it. More than 100 characters will automatically increase the height of NSTextView.
You can use the string addition [-NSString boundingRectWithSize:options:attributes:] to get a bounding rectangle. You might also want to look into the Layout Manager.
I have an NSTextField where the font used can be changed by the user.
Although the font's point size remains the same, the actual height of the font is much bigger for some fonts. This means if the user changes the font to 'Zapfino' for example, most of the text is cropped. I would like it so the text in the box always looks roughly the same size.
Also the line height seems to change depending on which font is used meaning they don't line up well and sometimes get pushed down and the bottom gets cropped off.
How can I keep the text size and line height looking the same?
You need NSTextField which is using single line. You can do it in Attributes inspector by checking Uses Single Line Mode.
How to do it:
And now Your text will be like this:
Do programatically:
To change NSTextField height programatically by font size or scale the text to fit the bounds example here.
I want to programatically create an NSTextView. How can I determine the correct frame height so that the view displays one line of text in the current default font?
The NSFont class has a method that can give you the size of a rectangle that would enclose a specific attributed string. Get the font used by your text view, create a string that serves as a reasonable example of what will be in the text view, and use that to inform your frame height. (The frame height will need to be some number of points larger than the actual rectangle the string would be displayed in.)
Alternately, you can get the various metrics from the font and attempt to calculate a reasonable frame from that. That might or might not work; for example, a font like Apple Chancery has a huge amount of variation depending on the glyphs that are being rendered, where they are in a word, and so on; I don't know that you can calculate what the needed size would be in advance without knowing exactly what you were going to render.
It would be more normal to be using an NSTextField than an NSTextView for a single line of text.
With NSTextField, just do the following:
[textField setFont:myFont];
[textField sizeToFit];
Oh, and there is no built-in 'current default font'. If an application has such a concept, it needs to track it itself. The font panel doesn't read or write to anything global, it's used to operate on specific text objects.