I've using xhtml,jsf and primefaces. I've mentioned my styles in css file. I want to add roboto font in my project. So i tried for adding font and got some solution, like adding below line in XHTML
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
But i don't want to add this line http://fonts.googleapis.com/cssto my code.
I want to add it through .CSS and XHTML file except web link.
Google Fonts offers three distinct ways to embed fonts, all of which are clearly described on their Quick Use page:
Standard
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
#import
#import url(http://fonts.googleapis.com/css?family=Roboto);
JavaScript
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Roboto::latin' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})(); </script>
These are the only ways to include them — or any web font for that matter.
You could go the route of using a Data URI for the font files
#font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: local('Roboto'), local('Roboto-Regular'), url(data:application/octet-stream;charset=utf-8;base64,<YOUR_BASE_64_ENCODED_FILES_SOURCE>) format('woff2');
unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F;
}
but that's highly discouraged as it would add unnecessary bloat to your page. Also, I'm not sure what the expected benefits of this approach would be in your case. It's usually only useful for very small binary files (~1-2k).
Related
Looking at the source for the Microsoft Edge homepage, the page's stylesheet is loaded as:-
<link rel="stylesheet" type="text/css" href="https://c.s-microsoft.com/en-gb/CMSStyles/style.csx?k=eb892833-0e5a-b8c0-2921-57013ef132d9_f05cbaf8-1aa4-2e42-0beb-040a76f09433_e688a192-b2e5-4598-dec4-9340a1bb6723_6e5b2ac7-688a-4a18-9695-a31e8139fa0f_b3dad3e4-0853-1041-fa46-2e9d6598a584_fc29d27f-7342-9cf3-c2b5-a04f30605f03_a66bb9d1-7095-dfc6-5a12-849441da475c_1b0ca1a3-6da9-0dbf-9932-198c9f68caeb_ef11258b-15d1-8dab-81d5-8d18bc3234bc_11339d5d-cf04-22ad-4987-06a506090313_176b8afa-bab9-e793-c91f-d22b5a134b6e_8031d0e3-4981-8dbc-2504-bbd5121027b7_3f0c3b77-e132-00a5-3afc-9a2f141e9eae_aebeacd9-6349-54aa-9608-cb67eadc2d17_0cdb912f-7479-061d-e4f3-bea46f10a753_343d1ae8-c6c4-87d3-af9d-4720b6ea8f34_a905814f-2c84-2cd4-839e-5634cc0cc383_190a3885-bf35-9fab-6806-86ce81df76f6_9a16c79d-25f5-bdfe-5f2f-db073a7c44a9_e35b6b5f-66da-dedc-3f00-745165d9153a_469a8551-3011-f265-8b8f-5929dc69c497_788198f9-9eef-398f-9683-0cfdba85933d_bfafe587-a6ac-831e-ddf2-924fd9c72cdf_cab08b69-d2f0-1170-14b6-3c3a28953f9f" />
Digging further into the source for style.csx, the syntax of the file is scss like, for example:-
#mixin font-face($family, $set, $weight, $locals: (), $version: latest){
$local-fonts: '';
#if $supports-local == true {
#each $item in $locals {
$local-fonts: #{$local-fonts} + 'local("' + #{$item} + '"),';
}
}
#font-face {
font-family: 'wf_' + #{$family} + '_' + #{$weight};
src: url('//i.s-microsoft.com/fonts/#{$family}/#{$set}/#{$weight}/#{$version}.eot');
src: #{$local-fonts} +
url('//i.s-microsoft.com/fonts/#{$family}/#{$set}/#{$weight}/#{$version}.eot?#iefix') format('embedded-opentype'),
url('//i.s-microsoft.com/fonts/#{$family}/#{$set}/#{$weight}/#{$version}.woff') format('woff'),
url('//i.s-microsoft.com/fonts/#{$family}/#{$set}/#{$weight}/#{$version}.ttf') format('truetype'),
url('//i.s-microsoft.com/fonts/#{$family}/#{$set}/#{$weight}/#{$version}.svg#web') format('svg');
font-weight: normal;
font-style: normal;
}
}
Google didn't lead me to anything which seems to pertain to csx in this context - this isn't C# and doesn't seem to relate to a jquery plugin called csx which processes css files.
So, what exactly is a csx file in this context? Does it require javascript client side processing (the page renders fine in Chrome) and is there any benefit to csx used this way over, for example, pre-compiled scss?
In this case .CSX is almost certainly C# scripting. What you are seeing is the generated output of that script NOT the source of the file style.csx
I'm using PhantomJS to turn an html page into PDF. This page uses fonts from cloud.typography.com. Now the html page itself is fine, and if I manually print it to a PDF, that too is fine. However, when I use PhantomJS to turn it to a PDF, the server fonts do not show up.
I researched this issue, and while I could find general issues involving fonts, I could find nothing on this specific case. The closest thing I could find was a bug in which PhantomJS would use the fallback font even if the primary one was available, but removing the fallback font didn't fix the issue for me.
Is this a known bug? Did I do something wrong? Do you know of any work-arounds?
Here's the (generic) html to PDF rendering script I'm using. I'm parametizing the page on the command line:
var page = require('webpage').create(),
args = require('system').args,
if ( args[2].split('.').pop() == 'pdf' ) {
page.viewportSize = { width:1920, height:1080 };
page.paperSize = {
width: '8.5in',
height: '11in',
};
}
page.open(args[1], render);
function render() {
page.render(args[2]);
phantom.exit();
}
Here's a relevant html snippet that points to the font server and the style sheet:
<link rel="stylesheet" type="text/css" href="print.css">
<link rel="stylesheet" type="text/css" href="//cloud.typography.com/7787052/625786/css/fonts.css" />
And here's a relevant section from print.css that references the fonts:
body {
font-family: "Gotham SSm A", "Gotham SSm B", sans-serif;
font-weight: 400;
font-style: normal;
margin: 0;
padding: 0;
}
I have been using the Google Webfont loader to display parts of my website with nice fonts. I have this part work fine, all of my <p> show with the font I want. However, I would like only some classes of <p> (i.e. <p class="someclass">) to show with the webfonts, and then the rest with regular font (i.e. not Google Webfonts).
What is the best way for me to achieve this? At the moment, I am using this
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'McLaren' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>
<style type="text/css">
.wf-loading p.someclass {
font-family: serif
}
.wf-inactive p.someclass {
font-family: cursive
}
.wf-active p.someclass {
font-family: 'McLaren', cursive
}
</style>
and all <p> throughout the page display with the 'McLaren' font. I'm sure I am doing something dumb with the CSS selector but I'm not quite sure what.
Any help would be greatly appreciated. Thanks
First off you don’t necessarily need the js version of Google fonts I have just linked them through css and I have had no loading issues. Secondly, someone would need to see your body of your actual html BUT you don’t need the p prefix just add the fonts to your class .someclass{font-family:cursizve;} also like I said using css pseudo classes work better and a lot lighter on the client
I'm using v1.3.1 of PlayN. This issue is discussed in the following google groups thread but I'm not sure how to implement the suggestions proposed:
https://groups.google.com/forum/?fromgroups#!topic/playn/kiE2iEYJqM0
Perhaps someone can offer some sample code. Currently I'm following the technique referenced in the HTML link in this answer:
https://stackoverflow.com/a/9116829/1093087
My problem: on the home screen of my game, I display some text using loaded fonts. Works fine in Java version. However, in HTML version, the text doesn't display initially. On the next screen, or if I later return to the home screen, text is properly displayed. So I concluded that it was due to the asynchronous loading of fonts as discussed in the google groups thread.
My remedy was to add a splash screen that displays an image for a few seconds, giving the fonts a chance to load, before redirecting to screen with the text on it. But no matter how long I set the delay, the text is still not displayed.
Here's my HTML file which loads my game and the fonts:
<!DOCTYPE html>
<html>
<head>
<title>mygamePlayn</title>
<!-- fonts -->
<style>
#font-face {
font-family: "DroidSans-Bold";
src: url(mygame/fonts/DroidSans-Bold.ttf);
}
#font-face {
font-family: "UbuntuMono";
src: url(mygame/fonts/UbuntuMono-Bold.ttf);
}
</style>
</head>
<body bgcolor="black">
<script src="mygame/mygame.nocache.js"></script>
</body>
</html>
Here's my core Java code that generates the text that's not initially displaying (but works otherwise):
public static CanvasImage generateTextImage(String text, String fontName,
Integer fontSize, Integer fontColor, Style fontStyle, Integer padding) {
Font font = graphics().createFont(fontName, fontStyle, fontSize);
TextFormat fontFormat = new TextFormat().withFont(font).withTextColor(fontColor);
TextLayout layout = graphics().layoutText(text, fontFormat);
Integer width = (int) layout.width() + padding * 2;
Integer height = (int) layout.height() + padding * 2;
CanvasImage textImage = graphics().createImage(width, height);
textImage.canvas().drawText(layout, padding, padding);
return textImage;
}
I think I've finally figured out a solution to my problem. It required using Google WebFont Loader in the following somewhat roundabout fashion:
1) I saved the fonts -- in this case, DroidSans-Bold, Inconsolata, and UbuntuMono-Bold -- in my PlayN project's resources/fonts directory.
2) In resources/css, I add a fonts.css stylesheet where I add the #font-face definitions for my locally saved fonts. My fonts.css file:
#font-face {
font-family: DroidSans;
src: url('../fonts/DroidSans-Bold.ttf');
}
#font-face {
font-family: Inconsolata;
src: url('../fonts/Inconsolata.ttf');
}
#font-face {
font-family: UbuntuMono;
src: url('../fonts/UbuntuMono-Bold.ttf');
}
#font-face {
font-family: UbuntuMono;
font-weight: bold;
src: url('../fonts/UbuntuMono-Bold.ttf');
}
Note: I use the same value for my font-family name as that which I used for the font names in my PlayN code. For example, I load the DroidSans font in my PlayN code like this:
Font font = graphics().createFont("DroidSans", fontStyle, fontSize);
3) I then use Google WebFont Loader in my game's html file (MyGame.html) to load the fonts before the game loads. My MyGame.html file:
<!DOCTYPE html>
<html>
<head>
<title>MyGame</title>
<style>
body {
background-color:black;
color:white;
}
</style>
<!-- Google AJAX Libraries API -->
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1.4.2");
google.load("webfont", "1");
WebFontConfig = {
custom: { families: ['DroidSans', 'UbuntuMono'],
urls: [ 'mygame/css/fonts.css' ]
},
loading: function() {
console.log("loading fonts");
},
fontloading: function(fontFamily, fontDescription) {
console.log("loading font: " + fontFamily + "-" + fontDescription);
},
fontactive: function(fontFamily, fontDescription) {
console.log(fontFamily + "-" + fontDescription + " is active");
},
fontinactive: function(fontFamily, fontDescription) {
console.log(fontFamily + "-" + fontDescription + " is INACTIVE");
},
active: function() {
console.log("font-loading complete");
},
};
google.setOnLoadCallback(function() {
console.log("Google onLoad callback");
WebFont.load(WebFontConfig);
});
</script>
</head>
<body>
<div id="playn-root">
<script src="mygame/mygame.nocache.js"></script>
</div>
</body>
</html>
The console logging in the WebFont.load callbacks helped verify that the fonts were successfully loaded before the PlayN game code.
I would have preferred to use WebFont Loader with the fonts served through googleapis.com, but I couldn't figure out how to sync up the references between my PlayN code and the stylesheet. (Now that I look at it, if I didn't want to host the fonts myself, I suppose I could have just used the same url listed in the googleapi.com stylesheets.) Whatever the case, this pattern seems to solve the problem.*
*For Google Chrome. I haven't tested any other browsers.
I have a problem with printing web fonts from Google chrome v 18 but it works totally fine with IE and Firefox, I am using CSS file to pass the web fonts and the code for it is as follows.
#font-face {
font-family: 'C39P24DmTtNormal';
src: url('WebFonts/v100025_-webfont.eot');
src: url('WebFonts/v100025_-webfont.eot?#iefix') format('embedded-opentype'),
url('WebFonts/v100025_-webfont.woff') format('woff'),
url('WebFonts/v100025_-webfont.ttf') format('truetype'),
url('WebFonts/v100025_-webfont.svg#C39P24DmTtNormal') format('svg');
font-weight: normal;
font-style: normal;
}
Issue Screen-Shot:
Image Description:
In the above screen-shot all the ones marked in red are the bar-codes provided by the web fonts in CSS file but while printing are shown as above.
I tried to search on Google, but it seems to be a possible bug with Chrome and they are trying to fix it as soon as they can.
Is there any kind of workaround that can help me as I don't want my clients to install the fonts on each and every computer they use to browse my web application.
Put .svg at the start of the sources and try with different formats, like .svg as truetype:
#font-face {
font-family: 'EnzoOT-Medi';
src: url('font.eot');
src: url('font.svg') format('truetype'),
url('font.eot?#iefix') format('embedded-opentype'),
url('font.woff') format('woff'),
url('font.ttf') format('truetype'),
url('font.svg') format('svg');
font-weight: normal;
font-style: normal;
}
I also had the same problem of disabled print preview from the settings but the problem in Google Chrome. It does not allow the web fonts to get loaded before printing, so just enable it back.
If you are using Windows.print on body.onLoad then remove that as its the real cause of the problem. This is only supported by Internet Explorer and not Google Chrome.
Example:
<body onload="window.print();">
Remove the onload and I hope it does the trick. If you have tried this then I am sorry.
In my case it was due to the use of relative font-size in vw. I put a rule in #media print {} with size in pt and worked perfect. The funny thing was that it was only happening in Chrome.
The real fix for this issue is to not load the webfonts async on preformatted print pages. Doing so you can still use window.onload = window.print() to force the print dialog without any issues.
<script>
WebFontConfig = {
typekit: { id: 'xxxxxx' }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js';
wf.type = 'text/javascript';
wf.async = 'false';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
</script>