Permalink
Browse files

Add support to load fonts from file.

  • Loading branch information...
1 parent 8a5349e commit 1d3a99d85a51545b2f0dfbdb526303e1febbee65 @jviereck jviereck committed with tj Nov 15, 2012
View
@@ -5,20 +5,22 @@
'GTK_Root%': 'C:/GTK', # Set the location of GTK all-in-one bundle
'with_jpeg%': 'false',
'with_gif%': 'false',
- 'with_pango%': 'false'
+ 'with_pango%': 'false',
+ 'with_freetype%': 'false'
}
}, { # 'OS!="win"'
'variables': {
'with_jpeg%': '<!(./util/has_lib.sh jpeg)',
'with_gif%': '<!(./util/has_lib.sh gif)',
- 'with_pango%': '<!(./util/has_lib.sh pangocairo)'
+ 'with_pango%': '<!(./util/has_lib.sh pangocairo)',
+ 'with_freetype%': '<!(./util/has_cairo_freetype.sh)'
}
}]
],
'targets': [
{
'target_name': 'canvas',
- 'sources': [
+ 'sources': [
'src/Canvas.cc',
'src/CanvasGradient.cc',
'src/CanvasPattern.cc',
@@ -27,7 +29,7 @@
'src/Image.cc',
'src/ImageData.cc',
'src/init.cc',
- 'src/PixelArray.cc',
+ 'src/PixelArray.cc'
],
'conditions': [
['OS=="win"', {
@@ -47,6 +49,25 @@
'-lcairo'
]
}],
+ ['with_freetype=="true"', {
+ 'defines': [
+ 'HAVE_FREETYPE'
+ ],
+ 'sources': [
+ 'src/FontFace.cc'
+ ],
+ 'conditions': [
+ ['OS=="win"', {
+ # No support for windows right now.
+ }, { # 'OS!="win"'
+ 'include_dirs': [ # tried to pass through cflags but failed.
+ # Need to include the header files of cairo AND freetype.
+ # Looking up the includes of cairo does both.
+ '<!@(pkg-config cairo --cflags-only-I | sed s/-I//g)'
+ ]
+ }]
+ ]
+ }],
['with_pango=="true"', {
'defines': [
'HAVE_PANGO'
View
@@ -0,0 +1,50 @@
+
+/**
+ * Module dependencies.
+ */
+
+var Canvas = require('../lib/canvas')
+ , canvas = new Canvas(320, 320)
+ , Font = Canvas.Font
+ , ctx = canvas.getContext('2d')
+ , fs = require('fs')
+ , path = require("path");
+
+if (!Font) {
+ throw new Error('Need to compile with font support');
+}
+
+function fontFile(name) {
+ return path.join(__dirname, '/pfennigFont/', name);
+}
+
+var pfennigFont = new Font('pfennigFont', fontFile('Pfennig.ttf'));
+pfennigFont.addFace(fontFile('PfennigBold.ttf'), 'bold');
+pfennigFont.addFace(fontFile('PfennigItalic.ttf'), 'normal', 'italic');
+pfennigFont.addFace(fontFile('PfennigBoldItalic.ttf'), 'bold', 'italic');
+
+var canvas = new Canvas(320, 320)
+var ctx = canvas.getContext('2d')
+
+// Tell the ctx to use the font.
+ctx.useFont(pfennigFont);
+
+ctx.font = 'normal normal 50px "Times", serif';
+
+ctx.fillText('Quo Vaids?', 0, 70);
+
+ctx.font = 'bold 50px pfennigFont';
+ctx.fillText('Quo Vaids?', 0, 140);
+
+ctx.font = 'italic 50px pfennigFont';
+ctx.fillText('Quo Vaids?', 0, 210);
+
+ctx.font = 'bold italic 50px pfennigFont';
+ctx.fillText('Quo Vaids?', 0, 280);
+
+var out = fs.createWriteStream(__dirname + '/fontExample.png');
+var stream = canvas.createPNGStream();
+
+stream.on('data', function(chunk){
+ out.write(chunk);
+});
@@ -0,0 +1,108 @@
+FONTLOG
+Pfennig font family
+==========================
+
+This file provides detailed information on the Pfennig family of fonts.
+This information should be distributed along with the Pfennig fonts and
+any derivative works.
+
+
+Basic Font Information
+----------------------
+
+Pfennig is a sans-serif font with support for Latin, Cyrillic, Greek and Hebrew
+character sets. It contains sufficient characters for Latin-0 through Latin-10,
+as well as all modern Cyrillic scripts, the full Vietnamese range, modern Greek,
+modern Hebrew, and the Pan-African Alphabet. It supports the standard Roman
+ligatures and uses OpenType tables for diacritic placement.
+
+Pfennig supports the following Unicode ranges:
+
+Range Description Coverage
+..............................................
+U+0020-U+007F Basic Latin Full
+U+00A0-U+00FF Latin-1 Supplement Full
+U+0100-U+017F Latin Extended-A Full
+U+0180-U+024F Latin Extended-B 146/208
+U+0250-U+02AF IPA Extensions 32/96
+U+02B0-U+02FF Spacing Modifiers 18/80
+U+0300-U+036F Combining Diacritics 34/112
+U+0370-U+03FF Greek 74/134
+U+0400-U+04FF Cyrillic 214/256
+U+0500-U+052F Cyrillic Supplement 14/44
+U+0590-U+05FF Hebrew 27/87
+U+1DC0-U+1DFF Comb. Diacritic Supp. 4/43
+U+1E00-U+1EFF Latin Extended Add'l 173/256
+U+2000-U+206F General Punctuation 19/107
+U+2070-U+209F Super/Subscripts 1/42
+U+20A0-U+20CF Currency Symbols 1/26 (Euro sign only)
+U+2100-U+214F Letterlike Symbols 2/80
+U+2200-U+22FF Mathematical Operators 2/256
+U+25A0-U+25FF Geometric Shapes 1/96 (Dotted circle only)
+U+2C60-U+2C7F Latin Extended-C 5/32
+U+A720-U+A7FF Latin Extended-D 5/129
+U+FB00-U+FB06 Latin Ligatures 5/7 (all except archaic ligatures)
+
+ChangeLog
+---------
+
+2012-04-10 Added Cyrillic glyphs for Orok, Khanty, Nenets (in Unicode
+ pipeline)
+2012-04-07 Improved AE ligature and U+A78D; added a few glyphs with
+ diacritics.
+2011-09-24 Added a few African Latin glyphs; improved Cyrillic breve; major
+ spacing improvements in italics; improved TTF hints.
+2010-08-31 Further refinements of Vietnamese range in all faces.
+2010-08-04 Added several obscure African letters. Corrected some stacked
+ diacritics. Corrected proposed codepoint for H with hook.
+2010-06-23 Added modern Hebrew and Greek ranges
+2010-06-17 Added all anchors needed for diacritic attachment for
+ Pan-African to upright fonts; italic fonts are by nature unsuitable
+ for Pan-African due to stylistic clashes (e.g. between a and alpha).
+ Improved lowercase thorn in all fonts. Added dropped umlaut on A, O
+ and U in upright fonts, accessible as ss01.
+2010-06-04 Finished up requirements for Pan-African Alphabet;
+ improved Vietnamese italic & bold-italic
+2010-04-23 Completed support for all Cyrillic codepoints for modern
+ orthographies.
+2010-04-14 More glyphs: African, modern Pinyin, Amerindian
+2010-04-12 Moved non-Unicode glyphs to PUA; added a few more African
+ glyphs.
+2010-04-06 Diacritic improvement in Bold Vietnamese. Additional glyphs
+ for Skolt Sami, the Pan-Nigerian Alphabet, and various other
+ African languages.
+2010-03-31 Further spacing enhancements in non-italic. Improvements in
+ Vietnamese range in Medium to prevent excessive diacritic
+ height. Spacing improvements in italic ligatures.
+2009-09-18 Major overhaul of spacing in non-italic
+2009-08-06 Added Vietnamese range.
+2009-07-30 Kerned Latin ranges.
+2009-07-29 Added Cyrillic range.
+2009-07-24 Initial release
+
+
+Information for Contributors
+----------------------------
+
+This font is licensed under the Open Font License (OFL). There is no Reserved
+Name clause for the Pfennig font, enabling the free conversion between font
+formats.
+
+You can read more about the OFL here:
+http://scripts.sil.org/OFL
+
+If you'd like to make changes to the original font, you are free to contact
+the author of the original font (for contact information, please see the
+"Contributors" section below). Glyph changes should be in a FontForge .sfd
+file (please make sure your version of FontForge is reasonably up-to-date).
+Please send *only* the changed glyphs, not the entire font range. The author
+reserves the right to reject or modify any contributions. If your contribution
+is accepted, your name will appear in the Contributors section (unless you
+specify otherwise).
+
+
+Contributors
+------------
+
+Daniel Johnson (font maintainer)
+il.basso.buffo at gmail dot com
@@ -0,0 +1,93 @@
+Copyright (c) 2009 - 2012 Daniel Johnson (<il.basso.buffo@gmail.com>).
+
+This Font Software is licensed under the SIL Open Font License, Version 1.1.
+This license is copied below, and is also available with a FAQ at:
+http://scripts.sil.org/OFL
+
+
+-----------------------------------------------------------
+SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
+-----------------------------------------------------------
+
+PREAMBLE
+The goals of the Open Font License (OFL) are to stimulate worldwide
+development of collaborative font projects, to support the font creation
+efforts of academic and linguistic communities, and to provide a free and
+open framework in which fonts may be shared and improved in partnership
+with others.
+
+The OFL allows the licensed fonts to be used, studied, modified and
+redistributed freely as long as they are not sold by themselves. The
+fonts, including any derivative works, can be bundled, embedded,
+redistributed and/or sold with any software provided that any reserved
+names are not used by derivative works. The fonts and derivatives,
+however, cannot be released under any other type of license. The
+requirement for fonts to remain under this license does not apply
+to any document created using the fonts or their derivatives.
+
+DEFINITIONS
+"Font Software" refers to the set of files released by the Copyright
+Holder(s) under this license and clearly marked as such. This may
+include source files, build scripts and documentation.
+
+"Reserved Font Name" refers to any names specified as such after the
+copyright statement(s).
+
+"Original Version" refers to the collection of Font Software components as
+distributed by the Copyright Holder(s).
+
+"Modified Version" refers to any derivative made by adding to, deleting,
+or substituting -- in part or in whole -- any of the components of the
+Original Version, by changing formats or by porting the Font Software to a
+new environment.
+
+"Author" refers to any designer, engineer, programmer, technical
+writer or other person who contributed to the Font Software.
+
+PERMISSION & CONDITIONS
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the Font Software, to use, study, copy, merge, embed, modify,
+redistribute, and sell modified and unmodified copies of the Font
+Software, subject to the following conditions:
+
+1) Neither the Font Software nor any of its individual components,
+in Original or Modified Versions, may be sold by itself.
+
+2) Original or Modified Versions of the Font Software may be bundled,
+redistributed and/or sold with any software, provided that each copy
+contains the above copyright notice and this license. These can be
+included either as stand-alone text files, human-readable headers or
+in the appropriate machine-readable metadata fields within text or
+binary files as long as those fields can be easily viewed by the user.
+
+3) No Modified Version of the Font Software may use the Reserved Font
+Name(s) unless explicit written permission is granted by the corresponding
+Copyright Holder. This restriction only applies to the primary font name as
+presented to the users.
+
+4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
+Software shall not be used to promote, endorse or advertise any
+Modified Version, except to acknowledge the contribution(s) of the
+Copyright Holder(s) and the Author(s) or with their explicit written
+permission.
+
+5) The Font Software, modified or unmodified, in part or in whole,
+must be distributed entirely under this license, and must not be
+distributed under any other license. The requirement for fonts to
+remain under this license does not apply to any document created
+using the Font Software.
+
+TERMINATION
+This license becomes null and void if any of the above conditions are
+not met.
+
+DISCLAIMER
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
Oops, something went wrong.

0 comments on commit 1d3a99d

Please sign in to comment.