Icon font not applying in RubyMotion app - ios

Having an issue trying to use an icon font for scalable icons in a RubyMotion (ios) app.
I created a small set of icons from icomoon, and set the characters to 'A', 'B', and 'C'.
I imported this into the Font Book and it appears to respect the 'A', 'B', and 'C' characters:
To test, I fired up a word document and typed 'A', 'B', and 'C' and it appears to display fine:
Now, onto the RubyMotion app - I included the font in /resources:
(Loading Lobster and Open Sans from sub-directories work)
Then I reference the font in my Rakefile:
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'myapp'
app.fonts = ["OpenSans-Bold.ttf", "icomoon.ttf"]
end
In my controller, I add a label to the screen using the icomoon font:
#lblIcon = UILabel.alloc.initWithFrame([[0,0],[100,100]])
#lblIcon.text = "A"
#lblIcon.backgroundColor = UIColor.clearColor
#lblIcon.color = "#ffffff".to_color
ico_font = UIFont.fontWithName("icomoon", size:48)
#lblIcon.font = ico_font
self.view.addSubview #lblIcon
Now, when I run rake clean to force a refresh and rake to launch the simulator, the font doesn't seem to work:
If I use the RubyMotion inspector/REPL and drill down on the font, it say it is loading Helvetica, not icomoon as I intended:
I'm at a loss here on why I can't apply the icomoon font family and helvetica appears instead.
Any suggestions or ideas?

I have added my fonts in the 'resources' folder and successfully using them directly without manipulating app.fonts:
b.titleLabel.font = UIFont.fontWithName('Entypo', size: barHeight*1.1)
(the font I'm using is called Entypo.ttf)
Otherwise, the code you've pasted looks ok to me.

Related

Neovim: icons missing nvim-tree-web-devicons

I added nvim-devicons and installed one of the patched fonts:
https://www.nerdfonts.com/font-downloads.
the icons still not showing,
Config with packer:
https://github.com/kyazdani42/nvim-web-devicons
use({
"kyazdani42/nvim-tree.lua",
requires = {
"kyazdani42/nvim-web-devicons", -- optional, for file icons
},
})
This is my GitHub repo for this config:
https://github.com/azizgharbi/Neovim-config
Should i install all the icons ? because i only installed one of those icons which is big blue terminal.
I am on macOs and using iterm2.
Make sure to set the terminal font to use the patched font.
To change the font in iTerm2:
Start iTerm2.
Click iTerm2 → Preferences → Profiles → Text.
Choose the patched font on the right.

React-native unrecognized font family error

I wanted to use a custom font in my react-native project, but I got an error on ios simulator
How can I solve it
I tried every way but I couldn't find a solution.
Unrecognized Font Family: sfproregular
Error: Error Screenshot
Project Structure:
Project structure screenshot
react-native.config.js
module.exports = {
project: {
ios: {},
android: {}, // grouped into "project"
},
assets: ["./assets/fonts/"], // stays the same
};
versions
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-gesture-handler": "^1.7.0",
"react-native-phone-input": "^0.2.4",
"react-navigation": "^4.4.0"
I wanted to use the font in "Welcome.js"
Welcome.js
import React from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
Image,
StatusBar,
TouchableOpacity,
Button,
ImageBackground,
} from 'react-native';
import Logo from '../components/WelcomeLogo';
import arkaplan from '../assets/images/arkaplan.png';
export default class Welcome extends React.Component {
render() {
return (
<>
<ImageBackground source={arkaplan} style={styles.constrain} >
<StatusBar barStyle="light-content"/>
<Logo />
<Text style={styles.welcome} >Welcome!</Text>
</View>
</>
)
}
};
const styles = StyleSheet.create({
constrain: {
flex: 1,
alignItems:'center',
justifyContent:'center',
welcome: {
fontSize: 50,
color: 'white',
fontFamily: 'sfprogregular',
marginTop: 20,
marginBottom: 5,
},
});
Much like you I experienced this Unrecognized Font family issue when running the iOS build via Terminal. For whatever reason, it doesn't effect the final archive build or if one runs the build via Xcode. This is on the latest RN 0.63.3 in macOS Catalina 10.15.7 with Xcode 12.0.1.
The issue was with the font name itself.
Solution Summary
In your case, I recommend the following steps to take.
Install your font sfprogregular on your macOS system
With the font installed, and selected in Font Book press CMD+I to see postscript name
Rename the font files in your project to their respective PostScript names
Run npx react-native link in your project to setup the renamed fonts
Do cleanup of the older font files prior to the rename (remove old fonts)
Change the name of the font to the postscript name in code when referring to the font in styles
My experience detailed
In my case, we are using TradeGothic.
Initially, when we linked the font, the name of the font file itself was:
Trade Gothic LT.ttf
Android is fine with this, but not iOS. That's because Android relies on the filename, but iOS depends on the PostScript name of the font.
To fix this, I renamed the ttf file to it's postscript name TradeGothicLT.ttf. For the bold one which was Trade Gothic LT Bold.ttf I renamed it to TradeGothicLT-Bold.ttf.
I then did npx react-native link inside my project to connect my newly renamed fonts. Then, I cleaned up by removing the older .ttf files from the XCode project under resources (just press delete on each of the red font files that are no longer there) and removed the font files from the older Android link process in the folder /android/app/src/main/assets/fonts/. In the info.plist file, under the section UIAppFonts remove the older font filenames.
Finally in code, instead of referring to 'Trade Gothic LT' we now refer to it as 'TradeGothicLT'. That's it, it works now!
You can find the postscript name of the font by installing the .ttf file (double click it) on macOS and in Font Book with the font selected press CMD+I to get information about the font.
NOTE: It's not necessary to install the font to macOS, it's just the only way I know of to get the PostScript name. If you already have the PostScript name of the fonts, you don't need to install them.
I hope this helps you and others that might stumble upon this issue!
After adding the custom fonts, you need to link it using react-native link.
That will create an entry in Info.plist file (iOS) & android/src/main/assets/fonts/ directory (Android).
If the above command fails, you need to add those fonts manually in the android directory & plist file.
Sometimes your font name is not the same for Android and iOS (since iOS uses postscript name as fontFamily). In most cases, in android, the font is the same as the file, for example, I had this problem when using HelveticaNeueLTPro-BdEx font in iOS.
I am sharing the fix that helps me out.
Run npx react-native link. Maybe you already did.
Add this inside the didFinishLaunchingWithOptions method on your AppDelegate.m:
for (NSString *familyName in [UIFont familyNames]){
NSLog(#"Family name: %#", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"--Font name: %#", fontName);
}
}
Then, when you launch your app with xcode, you will be able to see all the fonts installed on your app, so you just have to use it the way it is listed on your console:
You can add fontFamily based on OS like:
Platform.OS == 'android' ? 'Linotype - HelveticaNeueLTPro-BlkEx' : 'HelveticaNeueLTPro-BlkEx'
Or you can rename the font file name and then run npx react-native link again and also maybe have to delete the previous UIAppFonts entry for the previously linked font in Info.plist file.

How to find the typeface of a TrueType font for PCL5 file generation?

I am trying to embed truetype font Treubuchet MS in a PCL5 generating program.
But I've stumbled on a problem. To embed and use the the font I should know its typeface, when selecting it for use in the *.pcl file. But I can't find a reference, where fonts and their typefaces(numbers) are described.
To be more precise, I am using the below sequence for selecting Treubuchet MS regular:
esc(s0S esc(s0B esc(s25513T esc(6982X
Explanation:
not italic, not bold, typeface of font, id of font to be loaded to printer.
But my currently selected typeface (25513) is wrong and the font is not sent and loaded to the printer (soft font added in the file).
Could you help me with this?
As far as I can see, the font ID you need is the one supplied when you created, and downloaded, the soft font.
Note that on page 189 of the PCL 5 reference (section 11-5 Soft Font Creation, in case you have a different version of the spec) it says:
Use the Font ID command to designate a unique ID number prior to the
download of a font header. If an existing font is already associated
with this ID, the existing font is deleted upon the download of the
font header.
The Font ID command can be found on p156 of my copy of the spec:
The Font ID command is used to specify an ID number for use in
subsequent font management commands. The ID number of a font can be
used to select the font for printing (refer to “Font Selection by ID”
in Chapter 8). E C *c#D
# = ID number Default = 0 Range = 0 - 32767 The font ID number is used during subsequent soft font downloads, selections or deletions. The
factory default font ID is 0 (if no Font ID command is sent, an ID of
0 is assigned).
So before you download the soft font you should specify the font ID of the font, eg:
esc*c1D
Then download the font. When you want to use the font you downloaded then you select it with:
esc(1X
Still not a PostScript question though :-)

Fonts not loading on iOS but load fine in Android

I'm currently loading two fonts from a qrc file. One of them is .ttf and the other is .otf. When I test my build on Android, they load and work fine (although the loading time is fairly long..)
However when I test it on my iPhone and/or simulator, none of the fonts load at all. They just seem to default back to Arial or something. Furthermore, only the .otf file works fine on Windows. The .ttf file defaults back to Arial and the characters are offset by 2 characters (so the word "ok" would be "qm")
What the hell is going on?
The fonts are located in:
"qrc:/fnt/res/fnt/MuseoSans_500.otf"
"qrc:/fnt/res/fnt/museo100-regular.ttf"
and I'm using this to load the fonts:
FontLoader {
id: museosans500
source: "qrc:/fnt/res/fnt/MuseoSans_500.otf"
}
FontLoader {
id: museo100
source: "qrc:/fnt/res/fnt/museo100-regular.ttf"
}
When accessing the fonts I set the font.family to museosans500.name and museo100.name. Like I said, they work fine on Android. But neither work on iOS, and only one of them works on Windows.
I'm using Qt Creator 3.4.0 and Qt 5.4.1.
Any help is much appreciated!
So I didn't solve it for Windows but this is an application for iOS and Android.
Basically I loaded the fonts through main.cpp instead with:
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
// Load custom fonts
if(QFontDatabase::addApplicationFont(QStringLiteral(":/fnt/res/fnt/MuseoSans_500.otf")) == -1)
qDebug() << "Failed to load font Museo Sans 500";
if(QFontDatabase::addApplicationFont(QStringLiteral(":/fnt/res/fnt/museo100-regular.ttf")) == -1)
qDebug() << "Failed to load font Museo 100";
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/res/qml/LoadScreen.qml")));
return app.exec();
}
Originally this didn't actually work. But that's because I was setting the font.family to be "Museo Sans 500" and "Museo 100" since that is what Windows would print in console when I asked for a full list of available font families.
When I printed out the font families list in Android, Mac and iOS I actually got "Museo Sans" and "Museo" respectively. Changing the font.family to those strings worked fine.
Unfortunately I have found no solution for Windows yet, but like I've said that doesn't matter to me.

Assets, rmagick and rails

I am working on developing an app that will generate a digital card from the user. At the moment I am working on the rmagick code in a .rb file. Then just running it from the command line untill I figure it all out. I am having a few problems.
The source image I can't figure out the path to it. the only way I can get it to work is if I place it in the controllers directory with the cards.rb file. I want to have it in assets/cards/
Saving the file, same issue as above. I want to save it in assets/cards/#card_id.png
I'm trying to use a custom font in the assets/fonts/ dir I've tried self.font = “#{RAILS_ROOT}/assets/fonts/dreamorphansbd.ttf” but the code will not run. If I remove the quotes it runs but the font is not correct.
The last thing and I have yet to try it is adding the caption as the card.event from the db. I'm think it will along those line but not sure.
require 'RMagick'
include Magick
blank = Magick::Image.read("Blank-Card.png").first
text = Image.read("caption:Some big long text would go here.") do
self.gravity = CenterGravity
self.font = #{RAILS_ROOT}/app/assets/fonts/dreamorphansbd.ttf
self.background_color= "Transparent"
self.size = "638x"
self.pointsize = 40
end
blank.composite!(text[0], CenterGravity, Magick::OverCompositeOp)
blank.write("card.png")
try: Magick::Image.read(Rails.root.join('image', 'Blank-Card.png')).first
try: blank.write(Rails.root.join('image', 'card.png'))
With: Magick.fonts, you will see all available fonts
try: Image.read("caption:#{obj_active_record.your_attribute}")

Resources