I'm trying to manually add a custom font to my localhost installation of WP, what I did so far:
download the font (Computer Modern) from fontsquirrel in .woff format
take the 4 files needed (Serif): Roman (cmunrm), Bold (cmunbx), Oblique (cmunti), Bold Oblique (cmunbi)
put the 4 files in the folder C:\xampp\htdocs\sitename\wp-includes\fonts\latex
write the following in style.css
CSS code
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunrm.woff');
font-style: normal;
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbx.woff');
font-weight: bold;
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunti.woff');
font-style: italic, oblique;
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbi.woff');
font-weight: bold;
font-style: italic, oblique;
}
body {
font-family: "Computer Modern", serif;
}
write the following in the WP editor
HTML code
This is normal text
<strong>This is bold text</strong>
<em>This is oblique text</em>
<em><strong>This is bold and oblique text</strong></em>
but the result is this
It seems that only Bold and Oblique have been loaded, in fact by replacing cmunti with cmunrm (Oblique with Roman) and cmunbi with cmunbx (Bold Oblique with Bold) in the CSS file this is showed
What is this due to, and how to solve it?
Does it help to be explicit with font-weight and font-style in each definition? That's what this answer does. It also adds css that makes strong/em associated to font-weight/font-style explicitly (which may be unneeded).
Don't know why but this solved the problem
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunrm.woff');
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunti.woff');
font-style: italic;
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbx.woff');
font-weight: bold;
}
#font-face {
font-family: "Computer Modern";
src: url('http://localhost/sitename/wp-includes/fonts/latex/cmunbi.woff');
font-weight: bold;
font-style: italic;
}
Related
For example the Victor Mono font has vastly different (ie. properly designed) Italic and Oblique styles, and I'm using it as my prefered programming font, however I can't seem to make it properly show both styles at the same time in code editors/text processors or on a webpage.
When I installed the font on my local system, both Italic and Oblique shows the Italic variant, I figured it might be an issue with the OS font system, so I tried to embed the fonts with CSS like this
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Oblique.ttf') format('truetype');
font-weight: normal;
font-style: oblique;
}
but now both
html {font-family:Victor Mono; font-weight:normal; font-style: italic;}
and
html {font-family:Victor Mono; font-weight:normal; font-style: oblique;}
shows the Oblique style. While if I re-order the #font-face rules to put the Italic one below the Oblique one like this
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Oblique.ttf') format('truetype');
font-weight: normal;
font-style: oblique;
}
#font-face {
font-family: 'Victor Mono';
src: url('VictorMono-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;
}
both Italic and Oblique styles will show the Italic variant. So it seems font-style: italic and font-style: oblique are actually interpreted as the same rule by the render engine and the rule appears later will override the former one?
So how should I show different italic and oblique font styles? For example I'd like VSCode to show comments in Italic style while reserved keywords in Oblique style. Currently it shows Italic all the time for both comments and reserved keywords which hurts my eyes when I look through the code.
I think its beacause of same font-family name, try this out:
#font-face {
font-family: 'Victor Mono Normal';
src: url('VictorMono-Regular.ttf') format('truetype');
font-weight: normal;
font-style: normal;}
#font-face {
font-family: 'Victor Mono Oblique';
src: url('VictorMono-Oblique.ttf') format('truetype');
font-weight: normal;
font-style: oblique;}
#font-face {
font-family: 'Victor Mono Italic';
src: url('VictorMono-Italic.ttf') format('truetype');
font-weight: normal;
font-style: italic;}
The dist css in the Github repo only links the italic version - I've seen issues when oblique is referenced in this way, so that may be causing problems. The demo site's css declares them separately like Fahim Khan's answer mentions, so that may be what you have to do if you want to reference them separately.
I'm not sure the designer intended for you to be able to use the three styles together like that, or how it would be done - the example code only uses the normal and italic together. IIRC, most editors have a separate bold font setting you can set to a different font - this may be how they're combining them in their editor, by setting that to the italic version.
I have a number of fonts which fall under the same font family name. I need to generate the #font-face for these fonts
Family Name: Test Pro
Font Name: TestPro-Cond
Font Name: TestPro-CondIt
Font Name: TestPro-It
I understand I can create a #font-face with whatever name I want and reference the font files. However I would like to follow the correct web standard. What I am unsure about is how to handle these 'condensed' fonts. Does anyone have experience with this?
Currently I have
#font-face {
font-family: "Test Pro Bold Condensed Italic";
src: url('./fonts/TestPro-BoldCondIt.otf');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Test Pro Bold Italic";
src: url('./fonts/TestPro-BoldIt.otf');
font-weight: normal;
font-style: normal;
}
Condensed fonts actually are basically a different family, if you think about it.
What you're doing is fine, but you can simplify the whole tree like this:
#font-face {
font-family: "Test Pro Condensed";
src: url('./fonts/TestPro-CondReg.otf');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Test Pro Condensed";
src: url('./fonts/TestPro-BoldCondIt.otf');
font-weight: bold;
font-style: italic;
}
#font-face {
font-family: "Test Pro";
src: url('./fonts/TestPro-Reg.otf');
font-weight: normal;
font-style: normal;
}
#font-face {
font-family: "Test Pro";
src: url('./fonts/TestPro-BoldIt.otf');
font-weight: bold;
font-style: italic;
}
And then only worry about using font-family: "Test Pro"; etc in your styles with the appropriate font-weight and font-style to trigger the heavier weight and/or italic version. The browser will automatically simulate any combinations you don't include (though it may look bad.)
Last thing, try to use woff and woff2 for the src if possible, the file size is much smaller.
It should be possible using the css property called font-stretch, but at the time of writing it's not covered in all major browsers.
See https://caniuse.com/#feat=css-font-stretch
I have written a web application which uses the yaml css framework. One of the lines in the yaml css file is....
#import url(http://fonts.googleapis.com/css?family=Droid+Serif:400,400italic,700|Droid+Sans:700);
The internet is very slow at my company and I want to replace that download with a local copy of the font.
To try to achieve this I went to http://www.google.com/fonts, downloaded the DroidSans and DroidSerif fonts. The files I get are...
fonts.DroidSerif-Italic.ttf
fonts/DroidSerif-BoldItalic.ttf
fonts/DroidSerif-Bold.ttf
fonts/DroidSerif.ttf
fonts.DroidSans.ttf
fonts/DroidSans-Bold.ttf
I then went to http://www.fontsquirrel.com/tools/webfont-generator and created 1 font kit for all my DroidSerif fonts and 1 font kit for all my DroidSans fonts.
I am a bit stuck now though because having a look at the demos in the generated font kits they have given a different font-face declaration per ttf file. In other words I have a number of font-face declarations...
#font-face {font-family: 'droid_serifbold'; ...
#font-face {font-family: 'droid_serifitalic'; ...
#font-face {font-family: 'droid_serifbold_italic'; ...
#font-face {font-family: 'droid_serifregular'; ...
...and same for droid sans...
But the yaml CSS framework doesn't use the fonts that way. Instead they have one definition of the font and then specify different font-weights...
body {
font-family: "Droid Serif", Georgia, "Times New Roman", Times, serif;
...
}
h6 {
font-family: "Droid Sans", Arial, Helvetica, sans-serif;
font-weight: 400;
q {
font-family: "Droid Serif", Georgia, "Times New Roman", Times, serif;
font-style: italic;
b {
font-weight: bold;
I would rather not change the yaml css as I might muck it up. My question is how can I change the font-face declarations provided to me from the font squirrel font kit to match the font-weight style my css is using?
thanks
If you go to the site you had in the first place: Google Fonts, and take a look at the generated code,
you can realize you need to:
Download these 4 files:
Droid Sans Bold
Droid Serif
Droid Serif Bold
Droid Serif Italic
Rename all appropriately and place in the fonts folder:
fonts/DroidSans-Bold.woff
fonts/DroidSerif.woff
fonts/DroidSerif-Bold.woff
fonts/DroidSerif-Italic.woff
And then use this code:
#font-face {
font-family: 'Droid Sans';
font-style: normal;
font-weight: 700;
src: local('Droid Sans Bold'), local('DroidSans-Bold'), url('fonts/DroidSans-Bold.woff') format('woff');
}
#font-face {
font-family: 'Droid Serif';
font-style: normal;
font-weight: 400;
src: local('Droid Serif'), local('DroidSerif'), url('fonts/DroidSerif.woff') format('woff');
}
#font-face {
font-family: 'Droid Serif';
font-style: normal;
font-weight: 700;
src: local('Droid Serif Bold'), local('DroidSerif-Bold'), url('fonts/DroidSerif-Bold.woff') format('woff');
}
#font-face {
font-family: 'Droid Serif';
font-style: italic;
font-weight: 400;
src: local('Droid Serif Italic'), local('DroidSerif-Italic'), url('fonts/DroidSerif-Italic.woff') format('woff');
}
Hi I have a quick question on use CSS #font-face to create a font family.
Traditionally, I used to setup my CSS fonts like this:
#font-face {
font-family: 'My Font Regular';
src: url('fonts/myfont.ttf');
}
#font-face {
font-family: 'My Font Bold';
src: url('fonts/myfont-bold.ttf');
}
p { font-family: "My Font Regular";}
strong {font-family: "My Font Bold";}
However I've recently discovered that you can do it like this:
#font-face {
font-family: 'My Font';
src: url('fonts/myfont.ttf');
font-style:normal;
font-weight:normal;
}
#font-face {
font-family: 'My Font';
src: url('fonts/myfont-bold.ttf');
font-style:normal;
font-weight:bold;
}
p {
font-family: "My Font" ;
font-style:normal;
font-weight:normal;
}
strong {
font-family: "My Font" ;
font-style:normal;
font-weight:bold;
}
My question is, if I use the second technique in bold for example, will the text still render using the custom .eot or will the browser try to emulate it without the using the actual bold font file?
Thanks
If your font file is a bolded font, it would be redundant to set font-weight: bold and there's no need to declare font-weight: normal since that is the default value. You should also use more than .eot files so you have a fallback for other browsers like the others suggested.
Here is an example of what I use:
#font-face {
font-family: 'Franklin Demi';
src: url('FranklinDemi.eot'),
url('FranklinDemi.ttf') format('truetype'),
url('FranklinDemi.svg#font') format('svg');
}
#font-face {
font-family: 'Franklin Heavy';
src: url('FranklinHeavy.eot'),
url('FranklinHeavy.ttf') format('truetype'),
url('FranklinHeavy.svg#font') format('svg');
}
.sidansTitel{
font-family: 'Franklin Demi';
font-size: 22pt;
color: #8b9ba7;
text-shadow: 0 1px 0 rgba(0,0,0,0.01);
}
.sidansTitel b{
font-family: 'Franklin Heavy';
font-weight: normal;
font-style: normal;
}
Setting both font-weight: normal; and font-style: normal; makes the font render well in ie/ff/chrome, without it it looked like crap in Chrome. I believe that it looked like crap in Chrome because it tried to render the bold font in bold, which should be fixed by this.
EDIT: spelling
On myfonts.com I purchased the Didot font which comes in regular, bold, italics and bold italics (one separate file for each of these styles).
When my WordPress users write articles with bold and italic characters, I want the corresponding font style to be used.
But so far, it is always the regular font which is used, even for italics or bold. As a result, the italics that I see on my site seem to be an "italics version" of my regular font. But this result is different from the real italics that is advertized on myfonts.com.
Their customer service is unable to help with these "development issues" in their own words. How can the proper font file be used for each style on my WordPress site?
Here is the code to add in CSS that myfonts.com provides with the files:
#import url("//hello.myfonts.net/count/xxxxx");
#font-face {font-family: 'LinotypeDidoteTextPro';font-weight: normal;font-style: normal;src: url('webfonts/xxxxxxx1.eot');src: url('webfonts/xxxxxxx1.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx1.woff') format('woff'),url('webfonts/xxxxxxx1.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro';font-weight: bold;font-style: italic;src: url('webfonts/xxxxxxx2.eot');src: url('webfonts/xxxxxxx2.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx2.woff') format('woff'),url('webfonts/xxxxxxx2.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro';font-weight: normal;font-style: italic;src: url('webfonts/xxxxxxx3.eot');src: url('webfonts/xxxxxxx3.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx3.woff') format('woff'),url('webfonts/xxxxxxx3.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro';font-weight: bold;font-style: normal;src: url('webfonts/xxxxxxx4.eot');src: url('webfonts/xxxxxxx4.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx.woff') format('woff'),url('webfonts/xxxxxxx4.ttf') format('truetype');}
Your #font-face declarations are all the same. you need them to each be different(LinotypeDidoteTextPro-normal, LinotypeDidoteTextPro-bold-italic, LinotypeDidoteTextPro-italic, LinotypeDidoteTextPro-bold) in order to use the declarations in your css. Also using classes like "bold" and "italic" instead of elements like "b" and "i" allow you to use the bold italic font properly, otherwise you have to choose which one to use.
CSS File should be:
#font-face {font-family: 'LinotypeDidoteTextPro-normal'; src: url('webfonts/xxxxxxx1.eot');src: url('webfonts/xxxxxxx1.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx1.woff') format('woff'),url('webfonts/xxxxxxx1.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro-bold-italic'; src: url('webfonts/xxxxxxx2.eot');src: url('webfonts/xxxxxxx2.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx2.woff') format('woff'),url('webfonts/xxxxxxx2.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro-italic'; src: url('webfonts/xxxxxxx3.eot');src: url('webfonts/xxxxxxx3.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx3.woff') format('woff'),url('webfonts/xxxxxxx3.ttf') format('truetype');}
#font-face {font-family: 'LinotypeDidoteTextPro-bold'; src: url('webfonts/xxxxxxx4.eot');src: url('webfonts/xxxxxxx4.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx.woff') format('woff'),url('webfonts/xxxxxxx4.ttf') format('truetype');}
body{
font-family: "LinotypeDidoteTextPro-normal";
font-weight: normal;
font-style: normal;
}
i,
.italic{
font-family: "LinotypeDidoteTextPro-italic";
}
b,
.bold{
font-family: "LinotypeDidoteTextPro-bold";
}
b i,
i b,
.bold.italic{
font-family: "LinotypeDidoteTextPro-bold-italic";
}
As #Albert pointed out (reference: http://www.456bereastreet.com/archive/201012/font-face_tip_define_font-weight_and_font-style_to_keep_your_css_simple/) you can work better with the browsers and be forced to override less if you use font-style and font-weight in your font-face declarations. So an optimized version would be:
#font-face {
font-family: 'LinotypeDidoteTextPro';
src: url('webfonts/xxxxxxx1.eot');
src: url('webfonts/xxxxxxx1.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx1.woff') format('woff'),url('webfonts/xxxxxxx1.ttf') format('truetype');
font-weight: normal;
font-style: normal;}
#font-face {
font-family: 'LinotypeDidoteTextPro';
src: url('webfonts/xxxxxxx2.eot');
src: url('webfonts/xxxxxxx2.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx2.woff') format('woff'),url('webfonts/xxxxxxx2.ttf') format('truetype');
font-weight: bold;
font-style: italic;}
#font-face {
font-family: 'LinotypeDidoteTextPro';
src: url('webfonts/xxxxxxx3.eot');
src: url('webfonts/xxxxxxx3.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx3.woff') format('woff'),url('webfonts/xxxxxxx3.ttf') format('truetype');
font-weight: normal;
font-style: italic;}
#font-face {
font-family: 'LinotypeDidoteTextPro';
src: url('webfonts/xxxxxxx4.eot');
src: url('webfonts/xxxxxxx4.eot?#iefix') format('embedded-opentype'),url('webfonts/xxxxxxx.woff') format('woff'),url('webfonts/xxxxxxx4.ttf') format('truetype');
font-weight: bold;
font-style: normal;}
body{
font-family: "LinotypeDidoteTextPro";
font-weight: normal;
font-style: normal;
}
i, .italic{ font-style: italic; }
b, .bold{ font-weight: bold; }
you're close, you just need to clean up your syntax: here's how i declare open sans regular for font-weights: regular and bold:
#font-face{font-family:"open_sansregular";
src:url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/open-sans-regular.eot");
src:url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/open-sans-regular.eot?#iefix") format("embedded-opentype"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/open-sans-regular.woff") format("woff"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/open-sans-regular.ttf") format("truetype"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/open-sans-regular.svg#open_sansregular") format("svg");
font-weight:normal; font-style:normal}
#font-face{font-family:"open_sansregular";
src: url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/bold/open-sans-bold.eot");
src: url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/bold/open-sans-bold.eot?#iefix") format("embedded-opentype"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/bold/open-sans-bold.woff") format("woff"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/bold/open-sans-bold.ttf") format("truetype"),
url("http://dev.bowdenweb.com/a/fonts/sans-serif/open-sans/bold/open-sans-bold.svg#open_sansbold") format("svg");
font-weight:bold; font-style:normal}
continue that code for the rest of your #font-face declarations, swapping out file urls and font-weight/font-style/font-(etc) and also make sure that this is declared atop the first style sheet in your document. you can see the whole thing here: http://dev.bowdenweb.com/a/css/sandbox01.css
also, i used fontsquirrel to generate the different font file formats.