UIFont fontWithName returns nil - objective-c

In my info.plist, I added a key "Fonts provided by application" and added EdwardianScriptITCStd.otf
But, when I try to get that font, it returns nil:
NSLog(#"%#", [UIFont fontWithName:#"EdwardianScriptITCStd"
size:16.0f]);
I printed the font families using [UIFont familyNames] and it's not there either:
(
Thonburi,
"Snell Roundhand",
"Academy Engraved LET",
"Marker Felt",
"Geeza Pro",
"Arial Rounded MT Bold",
"Trebuchet MS",
Arial,
Marion,
"Gurmukhi MN",
"Malayalam Sangam MN",
"Bradley Hand",
"Kannada Sangam MN",
"Bodoni 72 Oldstyle",
Cochin,
"Sinhala Sangam MN",
"Hiragino Kaku Gothic ProN",
Papyrus,
Verdana,
"Zapf Dingbats",
Courier,
"Hoefler Text",
"Euphemia UCAS",
Helvetica,
"Hiragino Mincho ProN",
"Bodoni Ornaments",
"Apple Color Emoji",
Optima,
"Gujarati Sangam MN",
"Devanagari Sangam MN",
"Times New Roman",
Kailasa,
"Telugu Sangam MN",
"Heiti SC",
"Apple SD Gothic Neo",
Futura,
"Bodoni 72",
Baskerville,
"Chalkboard SE",
"Heiti TC",
Copperplate,
"Party LET",
"American Typewriter",
"Bangla Sangam MN",
Noteworthy,
Zapfino,
"Tamil Sangam MN",
"DB LCD Temp",
"Arial Hebrew",
Chalkduster,
Georgia,
"Helvetica Neue",
"Gill Sans",
Palatino,
"Courier New",
"Oriya Sangam MN",
Didot,
"Bodoni 72 Smallcaps"
)
What am I missing?
Thanks!

My comments were starting to get lengthy, so I've decided to submit an answer instead :)
Custom fonts are only supported in iOS 3.2 and above, so make sure your Deployment Target build setting doesn't go back any farther than version 3.2.
Verify that the font is included in your build target (in the "Copy Bundle Resources" build phase)
Check the raw value of the key for "Fonts provided by application" to make sure it's correct. When viewing the *.plist in Xcode, right-click and choose "Show Raw Keys/Values", then verify the key is UIAppFonts.
I believe iOS requires the PostScript name for a font when using fontWithName: size:, which you can find/verify by opening the font in Apple's Font Book and typing command+I.
At one point, there was an issue with using custom fonts and UILabel. I am not sure if this problem still exists. The solution was to subclass UILabel and set the font therein.
If it still doesn't work, this Stack Overflow thread on custom fonts has quite a bit of info, you may have some luck there.
EDIT
There's no guarantee that I have the same font file as you, but on my machine the PostScript name is "EdwardianScriptITC"

If your font name include '-' character, replace it with space character. For instance, Arial-Bold.ttf is used like [UIFont fontWithName:"Arial Bold" size:10];

The font name to be used seems to be the "Family name" in the Font Book. I tried the PostScript name, but it does not always work. Family Name, as far as I can tell, has always worked up until now.
You can check this information, as mentioned in the above answer, inside Font Book, select the font and press cmd+I.
Hope this helps...

i was having the same issue. you can set font to a label from interface builder at storyboard. then get that font in debug mode from label like :
let cfnt = txtUsernameField.font
then click the i button on the little debug window and the family name of font will be writed on the console window. and you can use it like that :
txtUsernameField.font = UIFont(name: "MyriadPro-CondIt", size: 14)

I had this problem although I swore I had custom fonts working just fine previously.
Turns out I just needed to run "Clean" on my project in XCode project so it could re-establish the references.

The problem I ran into is that some of the fonts from the font family returned correctly while others returned nil.
For example:
MuseoSansRounded-500 valid
MuseoSansRounded-900 nil
It turned out that Xcode was automatically including custom fonts that had been used in Interface Builder. I had used the 500 weight font in IB but not the 900 weight one.
These two steps fixed it for me:
In Build Settings, find and disable Auto-Activate Custom Fonts. There were two instances of this in my project.
On app launch, manually register the custom fonts with the system. I used the snippet from this SO answer: https://stackoverflow.com/a/32600784/131378
In the name of completeness, I could have left Auto-Activate Custom Fonts turned on and then skipped registering those fonts in code. However, I didn't want to update the code during development if I ended up using a new font in IB that was previously being registered manually. Xcode complains if you register a font that was already auto-activated.

Related

Matplotlib Tex Set Font

I would like to have a matplotlib plot in my Latex document that uses the same font as the rest of the document. I read in the matplotlib documentation that if you set the rc parameter 'usetex' to true it will use the 'Computer Modern' font, which is also the standard for Latex.
Trying this gave me the following result.
The title of the plot is generated by matplotlib, the caption by the Latex document. As you can see, the font doesn't match. I think both use 'Computer Modern', but not the same font family. The title (by matplotlib) might be something like 'Sans Serif Roman', while the caption (by the Latex document) is something like 'Serif Roman'. I tried to change the font family with the following:
plt.title("Lorem Ipsum", family='serif', fontsize=20)
But it has no effect as long usetex is activated. I also tried it with fontdict, but it also did not change the font in any way. Also writing the name of a font directly to family does not work.
Is there any way to get the same font as in the Latex document?
Ok, after speding yesterday half a day with searching a solution, I now stumbled over it 5 minutes after asking the question.
Solution:
plt.rcParams['font.family'] = 'serif'
For some reason when usetex=True, setting the fontfamily works only globally.

How do you add expo-google-fonts so they can work with fontFamily without the weights?

In the examples from https://docs.expo.dev/guides/using-custom-fonts/ it places the font family with the weight.
How do I make it so that I can use fontFamily and fontWeight and fontStyle to make it resolve to the appropriate font when I do
<Text fontFamily="Nunito" fontWeight="700" fontStyle="italic">700 weight italic</Text>
First
You have to get the file for the font of desired weight.
Ex: Poppins-Thin.ttf , Poppins-SemiBold.ttf, ...
Make sure all files are added and registered for your target OS(android/iOS) - https://www.bigbinary.com/books/learn-react-native/adding-custom-fonts
Second - (Optional, to get supported fonts)
Then get the font name, I use Font Book in MacOS (Note: Few fonts do not support weights)
Example:
'Poppins-SemiBold',
'Poppins-Thin',
'Poppins-Medium',
Third
<Text style={{fontFamily:'Poppins-MediumItalic'}} />
This is how our list of fonts look
Below is a sample of Font Book

How to embed font into pdf/a using iText7

I'm trying to see how to embed fonts into my pdf/a.
I found a lot of answer but using iTextSharp.
In my cas I use iText7 and all I tried gave me the error:
"All the fonts must be embedded..."
I have a ttf file for my font but I didn't find a way to embed it into my pdf to use it...
Could someone help me?
Thanks in advance
kor6k
As documented in the tutorial and as indicated by the error you mention ("All the fonts must be embedded"), you need to embed the fonts.
You are probably not defining a font, in which case the standard Type 1 font Helvetica will be used. These standard Type 1 fonts are never embedded, hence you need to pick another font.
The example from the tutorial uses the free font FreeSans:
public const String FONT = "resources/font/FreeSans.ttf";
The font object is defined like this:
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
This font is used in a Paragraph like this:
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("Font is embedded"));
document.Add(p);
This is the C# version. If you need the Java version, take a look at the Java version of the tutorial:
public static final String FONT = "src/main/resources/font/FreeSans.ttf";
PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.setFont(font);
p.add(new Text("Font is embedded"));
document.add(p);
If you already use this approach, and you still get the error, you probably have some content somewhere for which you didn't define a font that is embedded.

Grails, rendering plugin removes exotic characters

I want the plugin to create pdf-files and that works well when you only use standard characters but if you want special polish characters they don't show up. For example: "Wartość" will be "Warto".
I found the following recommendation:
<style>
#font-face {
src: url(path/to/arial.ttf);
-fs-pdf-font-embed: embed;
-fs-pdf-font-encoding: cp1250;
}
body {
font-family: "Arial Unicode MS", Arial, sans-serif;
}
</style>
But how can I make this work? url(path/to/arial.ttf) How do I do that, cant find any .ttf-file on WIN10 and how can I make it work on a deployment?
If I try to use any font on C:\windows\Font\ I get Null pointer exception. Probably b'cause there is no file with that name or path wrongly expressed.
Please help, I thought it should be a simple thing to create a polish version of a report but this became a disaster.

Adding Arial Unicode MS to CKEditor

My web application allows user to write rich text inside CKEditor, then export the result as PDF with the Flying Saucer library.
As they need to write Greek characters, I chose to add Arial Unicode MS to the available fonts, by doing the following :
config.font_names = "*several fonts...*; Arial Unicode MS/Arial Unicode MS, serif";
This font is now displayed correctly in the CKEditor menu, but when I apply this font to any element, I get the following result :
<span style="font-family:arial unicode ms,serif;"> some text </span>
As you can notice, I lost the UpperCase characters. This has pretty bad effect during PDF export, as then Flying Saucer doesn't recognise the font and so uses Helvetica which does not support Unicode characters, so the greek characters are not displayed in the PDF.
If I change manually from code source
<span style="font-family:arial unicode ms,serif;"> some text </span>
to
<span style="font-family:Arial Unicode MS,serif;"> some text </span>
then it is working as expected, greek characters are displayed.
Has anyone met this problem before? Is there a way to avoid UpperCase characters to be changed to LowerCase?
I really want to avoid doing any kind of post-processing like :
htmlString = htmlString.replace("arial unicode ms", "Arial Unicode MS");
I agree with you regarding resolving this issue aside from Flying Saucer R8.
Although depending upon your workflow, would it be more efficient to allow CKEditor to preprocess and validate a completed HTML encoded file (render the entire document to HTML first)?
None of the CKEditor support tickets specify the true source of the issue, so I recommend confirming for yourself whether it is (A) a styling issue, or (B) a CSS processing issue, or (C) a peculiar CKEditor parsing issue.
A possible workaround:
Make a copy of the desired unicode font and import it into Type 3.2 (works on both Mac and Windows).
http://www.cr8software.net/type.html
rename the duplicate font set into something all lowercase.
Limit your font selection
config.font_names = "customfontnamehere";
Apply the style separately (unicode typeface greatvibes below) and see if that gives you the desired result:
var s = CKEDITOR.document.$.createElement( 'style' );
s.type = 'text/css';
cardElement.$.appendChild( s );
s.styleSheet.cssText =
'#font-face {' +
'font-family: \'GreatVibes\';' +
'src: url(\'' + path +'fonts/GreatVibes-Regular.eot\');' +
'}' +
style;
If the above does not work, you can try to modify the xmas plugin.js (also uses the unicode typeface greatvibes and does all sorts of cool manipulations before output), so it might be worth trying to modify it rather than start from scratch:
'<style type="text/css">' +
'#font-face {' +
'font-family: "GreatVibes";' +
'src: url("' + path +'fonts/GreatVibes-Regular.ttf");' +
'}' +
style +
'</style>' )
Whichever approach you try, the goal is to test various styling and see if CKEditor defaults back to Helvetica again.
Lastly, the CKEditor SDK has excellent support, so if you have the time and energy, you could write a plugin. Sounds daunting, I know, but notice how the plugin.js within the /plugins/font directory has priority for size attributes.
If you are not interested in producing your own plugin, I recommend contacting the prolific ckeditor plugin writer
doksoft
(listed both on their website and on his own website) and ask for a demo of his commercial plugin "CKEditor Special Symbols" which has broad unicode capability.
Hope that helps,
ClaireW
I didn't find any way to do it with Flying Saucer R8, but you can make it work using Flying Saucer R9.
The method
ITextResolver.addFont(String path, String fontFamilyNameOverride, String encoding, boolean embedded, String pathToPFB) allow you to add the fond with a specific name.
Code sample:
ITextRenderer renderer = new ITextRenderer();
// Adding fonts
renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "arial unicode ms", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);
renderer.getFontResolver().addFont("fonts/ARIALUNI.TTF", "Arial Unicode MS", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, null);
String inputFile = "test.html";
renderer.setDocument(new File(inputFile));
renderer.layout();
String outputFile = "test.pdf";
OutputStream os = new FileOutputStream(outputFile);
renderer.createPDF(os);
os.close();
You can find Flying Saucer R9 on Maven.
The simplest solution (until CKEditor fixes that bug) is to do that post-processing.
You can do it on the server (really simple, you already have the code) or with a little CKEditor plugin, but that will give you the solution that you want and unless you need to add more fonts it will work without any further changes.