is it possible to get the font name and its size of a specific character in string in Swift?
I want to make a textview in which you can type with different fonts. I did this, but the problem is for example if something, lets say "hello" is written in Helvetica 16pt, and my current font Helvetica 24 pt, and then I want to write something more in "hello", let say "helloworld". This is possible in swift using attributed strings, but the word "hello" will be 16pt, and the word "world", will be 24pt. So, how to detect the font of the "hello" word, and then change the font automatically, and continue typing with the same font?
You should have a look at the NSAttributedString documentation. The font size attribute you mentioned is actually contained within the NSFontAttributeName key, which stores an NSFont which has both font type and size. You can directly access that using fontAttributesInRange: if you know where you want to look in the string.
Related
I am currently beginning to write functions for WoW WeakAura addons that use the WoW Lua in order to create the addon. I am trying to change the fonts within the printed string so that I have a Header essentially.
The code is essentially as follows:
return string.format("|cFFFFFFFFHeader Text|r\nRegular Text|r\nMore Regular Text|r\nEven More Regular Text")
The current printing returns all of the text the same size, but I just want to make the "Header Text" a size larger. I've found how to modify the colors, but I have yet to find anything similar for font size. Can someone assist?
I'm trying to convert pdf file to image.
Command: gs -sDEVICE=pngalpha -sOutputFile=cover.png -r144 myfile.pdf
Output:
Can't find CID font "MyStrangeNonEmbeddedFont".
Attempting to substitute CID font /Adobe-Identity for /MyStrangeNonEmbeddedFont, see doc/Use.htm#CIDFontSubstitution.
The substitute CID font "Adobe-Identity" is not provided either. attempting to use fallback CIDFont.See doc/Use.htm#CIDFontSubstitution.
Loading a TT font from /some/path/DroidSansFallback.ttf to emulate a CID font Adobe-Identity ... Done.
Font is successfully substituted with DroidSansFallback.ttf, but all characters are incorrect. Examples:
'C' is substituted with '<'
'6' is substituted with '>'
'B' is substituted with '#'
'D' is substituted with 'B'
Is it possible to fix it?
Too long for a comment, added as an answer instead.
This is why the PDF specification strongly suggests embedding CIDFonts.
Character code -> CID -> Glyph description is a complex area of the specification, more so than for regular fonts.
The only way you are going to get this correct is to use the original font that was not embedded. Your best bet to 'fix' this is to embed the font and make a new PDF file.
If you can't do that then you can source the font and add a specific entry to cidfmap.
Failing that then you can try editing the CMap in the PDF file (the CMap maps character codes to CIDs) or the character codes in the document, to match whatever font you have available (this is likely to be a lot of work).
The Ordering of the CIDSystemInfo 'might' give you some clues, you may be able to use the Registry and Ordering to determine how CIDs relate to actual glyphs.
If you have a genuine CIDFont to use as a substitute might be able to manipulate the CIDs of the glyphs, but that will be hard. If you are using a TrueType font as a substitute fro a CIDFont then you can't alter the CMap which Ghostscript will produce for that CIDFont.
I am working with Actionscript 3 in Flash, and I have a dynamic text field, instance called "textField" inside an instance of movie clip "mcpoo" and a keyframe with actionscript:
addEventListener(Event.ENTER_FRAME, myfunc);
function myfunc(e:Event):void{
mcpoo.textField.text = "this is a test string";
}
When I set the text field to a default value via text tool, e.g., "asdf" and test the movie, the text will change to include ONLY the chars in the default value, stripping out the rest. "this is a test string" is displayed as "ssass".
Why the good gawddam would it do something like this? As a corollary, how can I work around this or avoid it?
You need to embed more characters in the font you are using. By default, Flash will only embed the characters that you put in the field at author time. It does this to reduce file size.
Select the textfield and hit the Embed button in the Properties panel.
From there you can select the range of characters you want to include (under Character Ranges). You probably want to limit it to only the characters you will need, as it will add to the file size of the SWF.
Alternately, you could use a system font and forget about embedding anything.
I am trying to send data to a specific MergeField. The data are sent correctly. Each line of the data has for specific characters. For example the data to the field may be:
12345 FIRST\nABCDE.F SECOND
(it cannot get the newline so i just so it through character \n)
Now in the printed document each character has its one width, '1' is smaller than 'E' for example. So the data are not alligned within the field. I tried the following fonts: Arial, Tahoma, Courier New. Nothing helped.
Any ideas? Thanks in advance.
Ps the data are sent through an executable built by Visual C++ 5.0!!
You should probably use a tab-stop based layout. Set your tab-stops every, say, centimetre or so (i.e. just big than the widest character in your font) and add a tab before each element that needs to be aligned.
With this you shouldn't need to find a fixed width font and can use something more attractive.
Edit: Out of interest, I wonder why you have no luck with Courier New which is fixed width.
Maybe you could post a screenshot somewhere so we can have a look at your problem in more detail.
Try Courier - it does not have kerning (kerning = variable character width)
Also in the Font window there is a check box that allows you to apply kerning to fonts of a certain size or above - setting this value to a large font size may remove kerning.
How do you determine the length of a string of text in Arial Bold font, and then center it in VB6?
We are not using a "label" or "picture box" to print the text to the screen. We are sizing the text on the fly, and allowing the user to scale the size of our application to their liking. We write the text to screen using code.
One way is to have a hidden picture box and setup the font specs of that picture box the way you want.
Then use the TextHeight and TextWidth methods of the PictureBox to take your measurements. The Units will be in whatever scalemode the Picture Box is set to.
If you are printing directly to the printer or form then just set your font FIRST then take your measurements.
To center it
MyText = "Hello World"
<displayarea>.FontName = "Arial"
<displayarea>.FontSize = 14
<displayarea>.FontBold = True
TextWidth = <displayarea>.TextWidth(MyText)
TextLeftCoordinate = <displayarea>.ScaleLeft+<displayarea>.ScaleWidth/2-TextWidth/2
<displayarea>.CurrentX = TextLeftCoordinate
<displayarea>.Print MyText
Substitute displayarea with whatever object you are using.
Based on your updated answer note that the hidden picture box suggestion isn't used to print. It is only get text measurement. However you are printing directly to the form so you just need to use the code example above.
I can't remember the specifics (it's been about 3 years since I last used VB 6), but there's a method on Form called something like "MeasureString". It takes the string, and measures it according to the font settings of the form.
Also, here's a comment posted by Jason Lepack in case I've misunderstood and over-complicated your requirements:
"Labels usually have an alignment property. If you set it to align to center then, regardless of the font face it should center in the label".
There are Win32 GDI functions you can invoke: see for example GetTextExtentPoint32 at http://msdn.microsoft.com/en-us/library/ms534223(VS.85).aspx
Your best option may be Form.TextWidth, which appears to return the width of a string in twips. I've just taken this approach in order to dynamically size a button based on the length of the label that needs to appear inside it.
There is also a corresponding function called Form.TextHeight which would allow you to do the same thing in the vertical dimension.
Make sure that you set the Font property of the form to match the Font property of the control you're intending to measure the text for, otherwise you'll get incorrect results.
Read more at http://msdn.microsoft.com/en-us/library/aa267168(VS.60).aspx