My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
jsfont  
jsfont module
doc
Updated May 31, 2009 by sou...@gmail.com

If something seems wrong or incomplete, please enter a comment at the bottom of this page.



- source - main - QA -

jsfont module

Support text rendering (text to image) from the following font format:

TrueType, Type 1, CID-keyed Type 1, CFF, OpenType TrueType, OpenType CFF, SFNT-based bitmap, X11 PCF, Windows FNT, BDF, PFR, Type 42


class jsfont::Font

- top - revision -

constructor

constructor( filePathName [, faceIndex = 0] )
Creates a new Font object and seletc the face to use.
arguments:
  1. string filePathName: the path of the font file.
  2. integer faceIndex: the index of the face to use.

Methods

DrawChar

imageObject DrawChar( oneChar )
Draws one char with the current face.
arguments:
  1. string oneChar: string of one char.
return value:
An image object that contains the char.

DrawString

imageObject | integer DrawString( text [, keepTrailingSpace = false] [, getWidthOnly = false ] )
Draws a string with the current face.
arguments:
  1. string text: the single-line text to draw.
  2. boolean keepTrailingSpace: if true, the last letter separator space is keept.
  3. boolean getWidthOnly: if true, the function will return the length (in pixel) of the text.
return value:
An image object that contains the text or the length of the text in pixel.

Properties

ascender

integer ascender
is the ascender length (in pixel) of the current face.
note:
The ascender is the portion of a letter in a Latin-derived alphabet that extends above the mean line of a font. That is, the part of the letter that is taller than the font's x-height.

descender

integer descender
is the descender length (in pixel) of the current face.
note:
The descender is the portion of a letter in a Latin alphabet that extends below the baseline of a font. For example, in the letter y, the descender would be the "tail," or that portion of the diagonal line which lies below the v created by the two lines converging.

width

integer width
is the maximum width (in pixel) of the current face.

size

integer size
is the size (in pixel) of the current face.

encoding

enum encoding
is the current encoding.
supported encodings:
see constants section below.

poscriptName

integer poscriptName
is the postscript name of the face.

useKerning

boolean useKerning
enable or disable kerning usage for the current face.
note:
Kerning is the process of adjusting letter spacing in a proportional font. In a well-kerned font, the two-dimensional blank spaces between each pair of letters all have similar area.

horizontalPadding

integer horizontalPadding
is the size (in pixel) of the horizontal padding of any drawn text i.e. the space before and after the text.

verticalPadding

integer verticalPadding
is the size (in pixel) of the vertical padding of any drawn text i.e. the space above and below the text.

letterSpacing

integer letterSpacing
is the length (in pixel) of the additional space added between each letter in a text.

italic

boolean italic
enable or disable italic.

bold

boolean bold
enable or disable bold.

Constants

Encoding constants
NONE
MS_SYMBOL
UNICODE
SJIS
GB2312
BIG5
WANSUNG
JOHAB
MS_SJIS
MS_GB2312
MS_BIG5
MS_WANSUNG
MS_JOHAB
ADOBE_STANDARD
ADOBE_EXPERT
ADOBE_CUSTOM
ADOBE_LATIN_1
OLD_LATIN_2
APPLE_ROMAN

Examples

example 1:
Write "Hello world" in the file text.png
LoadModule('jslang');
LoadModule('jsstd');
LoadModule('jsfont');
LoadModule('jsimage');
LoadModule('jsprotex');
LoadModule('jsio');

var f = new Font('arial.ttf');
f.size = 100;
f.verticalPadding = -16;
var img = f.DrawString('Hello world', true);

var t = new Texture(img);
var t1 = new Texture(t);

t.BoxBlur(10,10);
t1.OppositeLevels();
t.Add(t1);
t.OppositeLevels();
t.Add(1);

new File('text.png').content = EncodePngImage(t.Export());

- top - main -


Sign in to add a comment
Powered by Google Project Hosting