I'm creating a cross-platform application with Nativescript and Angular.
I had a custom font icon that I want to use. I had some svg files that I turned into a ttf file. When I use the chars with their unicode code it shows nothing.
What I've done is this:
Put the ttf file on /src/fonts/icomoon.ttf (the same level of app)
Insert this code on app.css file
.ico {
font-family: icomoon, icomoon;
font-weight: normal;
}
In the home.component.html file I'm using it like this:
<!-- other stuff -->
<Label row="0" col="1" text="&#E904;" class="ico" style="color:white; margin-right:20;" (tap)="showAlert()" />
Where am I wrong? Did I miss something?
P.S.: the unicode codes go from e900 to e907
P.P.S: I've already used Fontawesome and it works with this code. Now I want to use my own font and this code doesn't work.
EDIT
I use this guide and I modified something.
In home.component.html file I have:
<Label row="0" col="1" [text]="'ico-link' | fonticon" class="ico" style="color:white; margin-right:20;" (tap)="showAlert()" />
I addedd the file app/assets/icomoon.css in which I put this:
font-family: 'icomoon';
src: url('../../fonts/icomoon');
src: url('../../fonts/icomoon') format('embedded-opentype'), url('../../fonts/icomoon') format('woff2'), url('../../fonts/icomoon') format('woff'), url('../../fonts/icomoon') format('truetype'), url('../../fonts/icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
.ico {
display: inline-block;
font: normal normal normal 14px/1 icomoon;
font-size: inherit;
text-rendering: auto;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.ico-link:before {
content: "\ue904";
}
and in app.ts I added:
#NgModule({
bootstrap: [
AppComponent
],
imports: [
//...
TNSFontIconModule.forRoot({
'ico': './assets/icomoon.css'
})
]
//...
});
After all this it still doesn't work. The icon isn't show.
I have updated your playground here. It is working fine now.
In your html I am binding text like this.
<Label textWrap="true" text="{{iconmoonLbl}}" class="ico"></Label>
and in the .ts file I am using String.fromCharcode
this.iconmoonLbl = String.fromCharCode(0xe904);//'&#E904;'
I had the same issue, I notice that it is required to use the whole format , then I moved to that awesome icon plugin.
Try
<Label row="0" col="1" text="" class="ico" style="color:white; margin-right:20;" (tap)="showAlert()" />
Also, remember that Android and IOs handle naming different, please check with using the new docs.
Note: In iOS your font file should be named exactly as the font name. If you have any doubts about the original font name, use the Font Book app to get the original font name.
Icon Fonts Nativescript/Angular
Related
Few days ago I found mdBook. Looking around for an easy, small, not
oveloaded static site generator, I'm excited. It's easy to use, simple,
fast and completely well designed.
In spite of an easy an fast setup, details hold problems inside. I'd like
to tweak the font in a customized theme.
In the mdBook manual font configuration possibilities are only mentioned
with the HTML renderer options:
A 'copy-fonts' config option copies 'fonts.css' and respective font files
to the output directory to be used in the default theme.
But reading a few bullet points above 'default-theme' is defined as the theme color
scheme to select by default in the 'Change Theme' dropdown.
How does that fit together? In my configuration the automatic copying of font files
does not work. I wrote a little bash script that does the copying after building book output.
So I'd like to describe the configuration steps I did:
set up a new book with copying the default theme's basic files into
a separate directory:
mdbook init testBook --theme
rename the 'theme' directory to 'peters-theme'
create new directory 'peters-theme/fonts
copy the Libertinus TeX font into this directory
create a new css file 'peters-theme/fonts/libertinus-sans-font.css'
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: normal;
src: url('LibertinusSans-Regular.otf') format('opentype');
}
#font-face {
font-family: libertinus-sans;
font-style: italic;
font-weight: normal;
src: url('LibertinusSans-Italic.otf') format('opentype');
}
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: bold;
src: url('LibertinusSans-Bold.otf') format('opentype');
}
tweak file 'peters-theme/css/general.css'
add additional css import rule
#import '../fonts/libertinus-sans-font.css'; /* added individually: use 'libertinus sans' fonts */
change HTML selector
html {
font-family: libertinus-sans; /* added individually: use 'libertinus sans' fonts */
color: var(--fg);
background-color: var(--bg);
text-size-adjust: none;
}
create file 'peters-theme/fonts/libertinus-sans-font.css'
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: normal;
src: url('LibertinusSans-Regular.otf') format('opentype');
}
#font-face {
font-family: libertinus-sans;
font-style: italic;
font-weight: normal;
src: url('LibertinusSans-Italic.otf') format('opentype');
}
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: bold;
src: url('LibertinusSans-Bold.otf') format('opentype');
}
place font files into 'peters-theme/fonts' directory
'peters-theme/fonts/LibertinusSans-Bold.otf'
'peters-theme/fonts/LibertinusSans-Italic.otf'
'peters-theme/fonts/LibertinusSans-Regular.otf'
tweak file 'peters-theme/index.hbs'
<!-- Fonts -->
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
{{#if copy_fonts}}
<!-- added additionally to include custom font CSS -->
<link rel="stylesheet" href="{{ path_to_root }}fonts/libertinus-sans-font.css">
{{/if}}
create bash script 'build-book.sh' (with copying as workaround)
#!/bin/bash
#
# Author: Peter
# Date: 2020-11-20
#
ROOTFOLDER='/home/peter/Documents/Peter/Notes/mdBook/testBook/'
#
# change to book directory
cd $ROOTFOLDER
#
# clean up old book files
mdbook clean
#
# build the book
mdbook build
#
# copy fonts for custom theme
cp -r ./peters-theme/fonts/ ./book/
#
# display book in browser
mdbook serve --open
Greetings
Peter
Additional information
Unfortunately, the first hint above doesn't solve the problem completely. It causes one effects: The custom font css file is copied to the correct
subdirectory automatically. It's new location is
book/peters-theme/fonts/libertinus-sans-font.css
In consequence, I changed the tweak of file 'peters-theme/index.hbs'
accordingly.
<!-- Fonts -->
<link rel="stylesheet"
href="{{ path_to_root }}FontAwesome/css/font-awesome.css">
{{#if copy_fonts}}
<!-- added additionally to include custom font CSS -->
<link rel="stylesheet"
href="{{ path_to_root }}peters-theme/fonts/libertinus-sans-font.css">
{{/if}}
But one part of the problem is remaining.
The local font files are not copied to the destination 'book/fonts' directory.
Looking around at fulfilled pull requests led me to
this one. Following the descriptions, I changed the 'book.toml' configuration file
and added one new 'output.html.font' section.
[output.html.font]
enable = true
woff = true
The complete 'book.toml' configuration file is listed here:
[book]
title = "Rust Never Sleeps"
description = "An adventure getting in touch with mdBook and Rust"
author = "Peter"
language = "en"
multilingual = false
src = "src"
[output.html]
theme = "peters-theme"
default-theme = "rust"
copy-fonts = true
additional-css = ["peters-theme/fonts/libertinus-sans-font.css"]
[output.html.font]
enable = true
woff = true
Additionally I changed the font css file
'peters-theme/fonts/libertinus-sans-font.css' to match the woff font type.
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: normal;
src: url('LibertinusSans-Regular.woff') format('woff');
}
#font-face {
font-family: libertinus-sans;
font-style: italic;
font-weight: normal;
src: url('LibertinusSans-Italic.woff') format('woff');
}
#font-face {
font-family: libertinus-sans;
font-style: normal;
font-weight: bold;
src: url('LibertinusSans-Bold.woff') format('woff');
}
The woff font files are located in a 'peters-theme/fonts' directory
'peters-theme/fonts/LibertinusSans-Bold.woff'
'peters-theme/fonts/LibertinusSans-Italic.woff'
'peters-theme/fonts/LibertinusSans-Regular.woff'
I would expect that these local font files are copied to the output
directory... But this isn't happening.
Now I hope getting a golden hint what I'm doing wrong.
Greetings to you
Peter
I am trying to import a font (fontawesome version 4.4.0's webfont) I have located in a directory called 'fonts' inside my project:
I have read several StackOverflow posts and I'm trying to import it using #font-face inside css:
#font-face {
font-family: 'MyWebFont';
src: url('../fonts/fontawesome-webfont.eot');
src: url('../fonts/fontawesome-webfont.eot?#iefix') format('embedded-opentype'),
url('../fonts/fontawesome-webfont.woff2') format('woff2'),
url('../fonts/fontawesome-webfont.woff') format('woff'),
url('../fonts/fontawesome-webfont.ttf') format('truetype'),
url('../fonts/fontawesome-webfont.svg#svgFontName') format('svg');
}
And then using it in the body:
body {
margin: 0;
padding: 0;
font-family: 'MyWebFont';
}
However, it's not loading:
Any idea on why is this happening? I can actually see the expected font inside the files...
Thank you in advance.
Edit:
In the network tab in my browser's developer tools I can see the follwing info:
.
In the 'Response' tab inside Network, I get "failed to load response data". Maybe the problem is there?
Edit2:
Other fonts are being loaded just fine. For example, 'Raleway' (which is very similar, but not exactly the same. Notice the difference in the 'l'):
I am trying to get this font (I think it's Adobe's 'Proxima Nova', the same used in Fontawesome's site, that's the reason of the name)...
I think the problem is that font awesome is only for icons, not text.
If you go to fontawesome.com and remove this line of code:
.fa, .fas {
font-family: "Font Awesome 5 Pro";
}
You will see all the icons that have the class fa and fas will be just a rectangle.
You also need to give every element other fonts like:
.fab {
font-family: "Font Awesome 5 Brands";
}
.fa, .far, .fas {
font-family: "Font Awesome 5 Free";
}
Problem:
I'm attempting to use Abadi MT Condensed Extra Bold font. Unfortunately, I can't find any CDN's that provide this over an API. Is there something wrong with the css code that I'm using to pull in the fonts? I know for sure the stylesheet is being loaded.
Context
The font works when I have it turned on in my system's font book 100%, but not when disabled/removed -- but I understand that it's not practical to expect that every user is going to have that font. So given this, it does not work on an iPhone or Android device.
Am I better off finding a font in a CDN or, is it possible to make this work? Thanks!
Code:
****** fonts.css ********
#font-face {
font-family: 'serif';
src: url('../fonts/Abadi MT Condensed Extra Bold.eot');
src: local('☺'), url('../fonts/Abadi MT Condensed Extra Bold.woff') format('woff'), url('../fonts/Abadi MT Condensed Extra Bold.ttf') format('truetype'), url('../fonts/Abadi MT Condensed Extra Bold.svg') format('svg');
font-weight: normal;
font-style: normal;
}
***** layout.pug *******
doctype html
html(lang='en')
head
meta(charset='utf-8')
meta(name='viewport', content='width=device-width, initial-scale=1, shrink-to-fit=no')
meta(name='description', content='')
meta(name='author', content='')
title #{title}
//jquery
script(src='https://code.jquery.com/jquery-2.2.4.min.js')
script(src='https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js')
//shopify
script(src='http://sdks.shopifycdn.com/js-buy-sdk/v0/latest/shopify-buy.umd.polyfilled.min.js')
//custom cart
script(src="scripts/cart.js")
//popper
script(src='./vendor/popper/popper.min.js')
//bootstrap
script(src='./vendor/bootstrap/js/bootstrap.min.js')
//Favicons
link(rel='apple-touch-icon', sizes='57x57', href='/favicon/apple-icon-57x57.png')
......
......
// Bootstrap core CSS
link(href='vendor/bootstrap/css/bootstrap.min.css', rel='stylesheet')
//Gliphicons had to be pulled in separately
link(href='//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-glyphicons.css', rel='stylesheet')
// Custom fonts for this template
link(href='./stylesheets/fonts.css', rel='stylesheet')
// Custom styles for this template
link(href='./stylesheets/template.css', rel='stylesheet')
Attempted Solutions
I've already attempted solutions like this. Also my CSS code used to not have the entire fonts.css file.
I was able to figure this out, posting for anyone else that has the same issue.
I found this blob to help
So now my final code is
#font-face {
font-family: AbadiBold;
src: url('../fonts/Abadi MT Condensed Extra Bold.ttf') format('truetype');
src:
url("../fonts/Abadi MT Condensed Extra Bold.woff") format("woff"),
url("../fonts/Abadi MT Condensed Extra Bold.otf") format("opentype"),
url("../fonts/Abadi MT Condensed Extra Bold.svg#filename") format("svg");
font-weight: 400;
font-style: normal;
}
* {
font-family: AbadiBold
}
h1, h2, h3, h4, h5, h6, .text-heading {
font-family: AbadiBold
}
here is the page where I want to add custom font http://pgkweb.ru/temp/1/index.html
So the fonts are:
http://pgkweb.ru/temp/1/include/MyriadProCondRegular/MyriadProCondRegular.ttf
http://pgkweb.ru/temp/1/include/MyriadProCondRegular/MyriadProCondRegular.woff
http://pgkweb.ru/temp/1/include/MyriadProCondRegular/MyriadProCondRegular.otf
http://pgkweb.ru/temp/1/include/MyriadProCondRegular/MyriadPro-Cond.eot
And I call them from css (http://pgkweb.ru/temp/1/include/style.css):
/*FONTS*/
#font-face {
font-family: MyriadProCond;
src: url(include/MyriadProCondRegular/MyriadProCondRegular.ttf); /* Путь к файлу со шрифтом */
src: url(include/MyriadProCondRegular/MyriadProCondRegular.woff);
src: url(include/MyriadProCondRegular/MyriadProCondRegular.otf);
src: url(include/MyriadProCondRegular/MyriadPro-Cond.eot);
}
*, body, p,h3,h4 {
font-family: 'MyriadProCond', Arial, sans-serif;
color: #fff;
}
But as I see in FireFox code explorer it doesn't works (line-through). But why?
Your webfonts are inside the "include" folder, as is the stylesheet, i.e. they are both in the same folder, so you have to erase the folder name from the file path in the links, like:
src: url("MyriadProCondRegular/MyriadProCondRegular.ttf");
instead of
src: url("include/MyriadProCondRegular/MyriadProCondRegular.ttf");
the same with all the other URLs
Seems like you are missing quotes around each url, the syntax is also a little off:
#font-face {
font-family: MyriadProCond;
src: url('include/MyriadProCondRegular/MyriadPro-Cond.eot');
src: url('include/MyriadProCondRegular/MyriadProCondRegular.woff') format('woff'), /* Путь к файлу со шрифтом */
url('include/MyriadProCondRegular/MyriadProCondRegular.ttf') format('truetype'),
url('include/MyriadProCondRegular/MyriadProCondRegular.otf') format('otf');
}
See here: https://css-tricks.com/snippets/css/using-font-face/
If this doesn't work, check that the URLs are correct and the fonts are being downloaded (no 404 errors in the network tab).
I am using Icomoon in an application - I am having a problem with a small number of icons which will not display. I have downloaded all the icons via the Icomoon App and this is the latest version - all 450 are selected.
I have tried on just a blank page with no other CSS and they still don't work in case it was some CSS in my application causing it.
<link rel="stylesheet" type="text/css" href="/css/icons/icomoon/style.css" media="screen" />
<i class="icon-user"></i> User
<i class="icon-bars"></i> Bars
<i class="icon-search"><i> Search
In the above, bars displays fine but user and search do not.
Here is my style.css file (truncated):
#font-face
{
font-family: 'IcoMoon';
src:url('fonts/icomoon.eot');
src:url('fonts/icomoon.eot?#iefix') format('embedded-opentype'),
url('fonts/icomoon.svg#IcoMoon') format('svg'),
url('fonts/icomoon.woff') format('woff'),
url('fonts/icomoon.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
[class^="icon-"],
[class*=" icon-"]
{
display: inline-block;
vertical-align: middle;
line-height: 1;
}
[class^="icon-"]:before,
[class*=" icon-"]:before
{
font-family: 'IcoMoon';
font-weight: normal;
font-style: normal;
speak: none;
-webkit-font-smoothing: antialiased;
}
.icon-users:before {
content: "\92";
}
.icon-bars:before {
content: "\b8";
}
.icon-search:before {
content: "\a0";
}
If I open up icomoon.svg (the only one I can "edit") then 92 and a0 are both there:
<glyph unicode="" d="M734.994 154.626c-18.952 2.988-19.384 54.654-19.384 54.654s55.688 54.656 67.824 128.152c32.652 0 52.814 78.138 20.164 105.628 1.362 28.94 41.968 227.176-163.598 227.176-205.564 0-164.958-198.236-163.598-227.176-32.654-27.49-12.488-105.628 20.162-105.628 12.134-73.496 67.826-128.152 67.826-128.152s-0.432-51.666-19.384-54.654c-61.048-9.632-289.006-109.316-289.006-218.626h768c0 109.31-227.958 208.994-289.006 218.626zM344.054 137.19c44.094 27.15 97.626 52.308 141.538 67.424-15.752 22.432-33.294 52.936-44.33 89.062-15.406 12.566-27.944 30.532-35.998 52.602-8.066 22.104-11.122 46.852-8.608 69.684 1.804 16.392 6.478 31.666 13.65 45.088-4.35 46.586-7.414 138.034 52.448 204.732 23.214 25.866 52.556 44.46 87.7 55.686-6.274 64.76-39.16 140.77-166.454 140.77-205.564 0-164.958-198.236-163.598-227.176-32.654-27.49-12.488-105.628 20.162-105.628 12.134-73.496 67.826-128.152 67.826-128.152s-0.432-51.666-19.384-54.654c-61.048-9.634-289.006-109.318-289.006-218.628h329.596c4.71 3.074 9.506 6.14 14.458 9.19z" />
<glyph unicode=" " d="M992.262 88.604l-242.552 206.294c-25.074 22.566-51.89 32.926-73.552 31.926 57.256 67.068 91.842 154.078 91.842 249.176 0 212.078-171.922 384-384 384-212.076 0-384-171.922-384-384 0-212.078 171.922-384 384-384 95.098 0 182.108 34.586 249.176 91.844-1-21.662 9.36-48.478 31.926-73.552l206.294-242.552c35.322-39.246 93.022-42.554 128.22-7.356s31.892 92.898-7.354 128.22zM384 320c-141.384 0-256 114.616-256 256s114.616 256 256 256 256-114.616 256-256-114.614-256-256-256z" />
Additionally, in the demo html file created from the icomoon app all the icons from 7f (download) to a0 (search) show as blank - both the icons I am trying to use fall into this range.
Any idea why some will show but others will not?
The problem I encountered in IE11 & edge was that the uppercase variant was shown instead of the lowercase icon. This is because IE11/edge ignores the case when dealing with css-applied characters and just searches for the first 'match' in the font file.
As you can see in this picture, the lowercase 'g' maps to a trashbin-icon whilst the uppercase 'G' maps to a play-icon. IE11 & edge erroneously used the first uppercase variant.
You can test this possible cause by inspecting your font file using font forge and by explicitly declaring a "text-transform: lowercase/uppercase" in the css on the icon itself and see if that fixes it.
To ultimately fix this, I removed all uppercase letters from the icon font and re-mapped everything to other unicode characters and everything worked as expected. I found my solution in this article: Icon font behaving strangely in IE11
Did you try the solutions proposed in previous stackoverflow answers?
IcoMoon icons not working in Internet Explorer 8
Why does one of these font-face render in IE8, but the others don't?
Also, see http://adactio.com/journal/6555/
I found the solution. My problema was that just a few icons were not displaying at all, but after opening the html file that comes on the zip I saw those same icons were displaying correctly. So I saw the html and css and saw that to call the icon through a class the file was using to classes. The first one appears below the #font-face call that basically sets the style and family of the font, everything needed for the font to display correctly so call this class. The next example is using my classes and icomoon font files.
#font-face {
font-family:"icomoon";
src: url('fonts/icomoon.eot');
#font-face {
/*All the urls*/
}
/*THIS IS THE ONE YOU NEED TO CALL*/
.icomoon {
font-family: "icomoon";
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/*Better font rendering ======*/
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
When you create a new icon with icomoon you get a preview before download. If an icon has a label of 'multicolor' will not display. I created some icons in illustrator and imported them to the app. As I had silhouettes in white and backgrounds in white, the icons were kind of broken and couldn't be used.
Had to use pathfinder to fix them and make it just one color, also having line strokes kills your icons.