Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Labeling Basic Example #73

Merged
merged 101 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 76 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
d3dfef3
add font face
cgcostume Apr 6, 2018
d34d48f
refine font face, add glyph object
cgcostume Apr 6, 2018
63258de
quicksave
cgcostume Apr 12, 2018
901f7c8
refine typesetter
cgcostume May 10, 2018
662fa62
GlyphSequence was renamed to Label, so update comments
anne-gropler Jun 1, 2018
4973426
initial commit: hijacked the testrenderer (now using LabelRender)
anne-gropler Jun 4, 2018
b4a834a
stripped-down glyph shaders
anne-gropler Jun 4, 2018
634f9b7
fix: precision for float
anne-gropler Jun 4, 2018
8485777
added fontloader; untested
anne-gropler Jun 6, 2018
61b69ff
use fontloader; ToDo: copy source/data to build/data when installing
anne-gropler Jun 7, 2018
668f679
load font in onInitialize
anne-gropler Jun 7, 2018
aa5a43d
WIP: trying to typeset a label
anne-gropler Jun 8, 2018
3b5b4c7
Hello Glyph Texture!
anne-gropler Jun 11, 2018
99ed0cb
WIPcommit. idea: gather all vertex data in labelgeometry.
anne-gropler Jun 11, 2018
622678c
WIP: typesetting seems to work, tex coords don't
anne-gropler Jun 25, 2018
1899fb1
WIP: changed image loading, still not working (stays black)
anne-gropler Jun 25, 2018
fbb905c
texture coordinates seem right now.
anne-gropler Jun 26, 2018
549c57b
removed codes in comments
anne-gropler Jun 26, 2018
dd7cb94
introduced camera, fixes aspect ratio
anne-gropler Jun 26, 2018
57b8270
Deleted outdated comments. No functional changes.
anne-gropler Jun 26, 2018
0342bf2
build: copy data dir
anne-gropler Jun 27, 2018
5536ae0
WIP: draw arrays instanced; still not working
anne-gropler Jun 27, 2018
52ae73d
fixed: draw arrays instanced.
anne-gropler Jun 28, 2018
d7a343c
doc; cleaned up unused / unnecessary code
anne-gropler Jun 28, 2018
6ffbff6
avoid division by zero when converting from vec4 to vec3
anne-gropler Jun 28, 2018
a897ab8
3D-label, kind of. usertransform doesn't work yet
anne-gropler Jun 29, 2018
1851cd0
fix: transform for multiple labels (still seem kind of stretched)
anne-gropler Jun 29, 2018
22b6df3
deleted unused+duplicated+commented code.
anne-gropler Jun 29, 2018
0d2462a
font color black, different example transform.
anne-gropler Jun 29, 2018
56958a5
Merge branch 'master' into openll
anne-gropler Jun 29, 2018
c250c33
Merge branch 'master' into openll
anne-gropler Jun 29, 2018
b0fad3a
format new line
anne-gropler Jun 29, 2018
1fe0e06
merge fix: wizard precision byte
anne-gropler Jun 29, 2018
42f00eb
another merge fix: bad merged lines (syntax error)
anne-gropler Jun 29, 2018
5366de9
Rename LabelGeometry.ts to labelgeometry.ts
anne-gropler Jun 30, 2018
61f80fa
refactoring
anne-gropler Jul 2, 2018
8dec555
Merge branch 'master' into openll
anne-gropler Jul 2, 2018
bda4ae4
refactoring: fetchAsync+Promise instead of raw xmlhttp
anne-gropler Jul 2, 2018
2902ba4
Merge branch 'master' into openll
anne-gropler Jul 2, 2018
197bca6
export labeling classes
bwasty Jun 30, 2018
81c4ad8
updated changes from testrenderer to labelrenderer
anne-gropler Jul 2, 2018
5faa581
comment/doc about frame resizes that affect labels using pt sizes (as…
anne-gropler Jul 2, 2018
484764f
Merge pull request #1 from bwasty/openll_bw
anne-gropler Jul 2, 2018
59dba23
using Promise less archaic and verbose.
anne-gropler Jul 2, 2018
c3ceaf5
load fontFace completely asynchronously using Promises
anne-gropler Jul 3, 2018
232d6e0
Merge branch 'master' into openll
anne-gropler Jul 3, 2018
8953207
Merge pull request #2 from cginternals/master
anne-gropler Aug 14, 2018
c489bc3
Merge branch 'master' into openll
anne-gropler Aug 14, 2018
509aef6
fix: label scale was bad. plus: navigation!
anne-gropler Aug 14, 2018
c22fd5d
userTransform for label
anne-gropler Aug 17, 2018
5efe053
fix: line anchor was not applied to the last glyph of each label
anne-gropler Aug 17, 2018
6850c12
missing return typedefs
anne-gropler Aug 17, 2018
f7c28c5
different units possible for font size (world and px)
anne-gropler Aug 20, 2018
d27d99c
label stores its current extent
anne-gropler Aug 21, 2018
13c0fe5
deleted unused code (POLYGON_OFFSET_FILL)
anne-gropler Aug 22, 2018
d9e30f8
warn if not all required keys were provided by font file
anne-gropler Sep 11, 2018
7f41f11
fix comment
anne-gropler Sep 11, 2018
7db0c97
WIP: created new class
anne-gropler Sep 20, 2018
4c5184f
Position2Dlabel ready to use
anne-gropler Oct 2, 2018
850f918
fix: order of applied transforms for 2D label
anne-gropler Oct 2, 2018
abd645b
fix: direction for position2dlabel now uses signed angles;
anne-gropler Oct 2, 2018
600b532
typo fix
anne-gropler Oct 8, 2018
ef18084
Label in 3D space implemented, following the example of the OpenLL API
anne-gropler Oct 8, 2018
ca2800e
documentation; removed unused code
anne-gropler Oct 9, 2018
1cb2cf2
fix: z-coordinate for 3D-Label was ignored
anne-gropler Oct 9, 2018
52020da
Merge branch 'master' into openll
cgcostume Oct 9, 2018
7e76c93
Update pugconfig.js
cgcostume Oct 9, 2018
9568e0a
Update pugconfig.js
cgcostume Oct 9, 2018
848d8e5
Update gl-matrix-extensions.ts
cgcostume Oct 9, 2018
2654bf6
documentation of FontLoader, WIP: refactoring
anne-gropler Oct 10, 2018
a5dc2ab
log instead of console
anne-gropler Oct 10, 2018
8cc2904
rename: setBearing --> bearingFromFontBaseAndOffset
anne-gropler Oct 10, 2018
09ad802
for of --> forEach
anne-gropler Oct 10, 2018
1cb501a
fix: logIfs had bad condition
anne-gropler Oct 10, 2018
f87879b
documentation for idea on how to treat multiple glyph atlas pages
anne-gropler Oct 10, 2018
16afadd
// --> /* */
anne-gropler Oct 10, 2018
f45b10a
use path module instead of homebrew function
anne-gropler Oct 10, 2018
a326c59
error handling for when not all mandatory keys are provided
anne-gropler Oct 10, 2018
26d5127
shorter try-catch block and more early-returns for fontloader loading…
anne-gropler Oct 10, 2018
cc8e2b9
removed unused code
anne-gropler Oct 10, 2018
97f8fb6
template strings for identifier naming
anne-gropler Oct 10, 2018
a5138ee
renaming: tan --> tangent; and alike.
anne-gropler Oct 10, 2018
01b8983
renaming: data --> texCoords
anne-gropler Oct 10, 2018
443abfe
explicitly todo added
anne-gropler Oct 10, 2018
aca8dcc
documentation
anne-gropler Oct 10, 2018
516c74d
useful error handling for fontloader's Promises
anne-gropler Oct 11, 2018
9ed6b96
console.warn --> log(LogLevel.Warning, ...)
anne-gropler Oct 11, 2018
16bd403
doc refinement
anne-gropler Oct 11, 2018
7d8face
constructor for GlyphVertices
anne-gropler Oct 11, 2018
fcd0cbf
doc
anne-gropler Oct 11, 2018
38e6dc7
comment line breaks
anne-gropler Oct 11, 2018
8d23039
doc for label class
anne-gropler Oct 11, 2018
0c5b0ac
doc for labelgeometry
anne-gropler Oct 11, 2018
6972569
assert for webgl extension requirement
anne-gropler Oct 11, 2018
df919b3
doc for labelrenderer
anne-gropler Oct 11, 2018
6404aeb
floating point notation for non integer semantic
anne-gropler Oct 11, 2018
c684b4c
don't discard invisible glyph fragments
anne-gropler Oct 11, 2018
f1a79f4
format
anne-gropler Oct 11, 2018
eda05c1
doc for typesetter
anne-gropler Oct 11, 2018
f3b26b6
MAD optimization in shader + doc
anne-gropler Oct 11, 2018
8d80773
format; remove double-assignment
anne-gropler Oct 11, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pugconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const entries = ['index.pug'];
const assets = [
[websiteDir, buildDir, ['css/*.css', 'js/*.js', 'img/*.{svg,png}', 'fonts/*', '*.{svg,png,ico,xml,json}'], [], false],
['./source', buildDir, ['data/{colorbrewer,smithwalt}.json'], [], false],
['./node_modules/rxjs/bundles/', `${buildDir}/js`, ['rxjs.umd.min.js'], [], false]
['./node_modules/rxjs/bundles/', `${buildDir}/js`, ['rxjs.umd.min.js'], [], false],
['./source/data/', `${buildDir}/data`, ['*'], [], false],
['./source/data/opensansr144', `${buildDir}/data/opensansr144`, ['*'], [], false],
['./source/data/verdana', `${buildDir}/data/verdana`, ['*'], [], false],
];


Expand Down
1,845 changes: 1,845 additions & 0 deletions source/data/opensansr144/opensansr144.fnt

Large diffs are not rendered by default.

Binary file added source/data/opensansr144/opensansr144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
293 changes: 293 additions & 0 deletions source/fontface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,293 @@

import { assert } from './auxiliaries';

import { Context } from './context';
import { Glyph } from './glyph';
import { Texture2 } from './texture2';
import { GLfloat2, GLfloat4, GLsizei2 } from './tuples';
import { Wizard } from './wizard';


/**
* Font related data for glyph based text rendering. The glyph-based font face is described by, e.g., font-size,
* line spacing, a glyph catalogue, as well as kerning information. The glyph catalogue is based on a set of glyphs
* referring to a texture atlas (@see {@link Glyph}). All measures are provided in float even though most
* glyph-textures and associated font data is encoded via integer values. A font face explicitly relies on floating
* values to reduce the need of casting as well as to simplify the use for dpi aware text rendering. Most measures can
* be interpreted as points (by means of the unit pt), again, easing the use for arbitrary dpi.
* The font face interface is designed to access most basic font settings ascent, descent, and line gap (leading).
* Additional font settings are provided via interface but are derived from or mapped to the above mentioned three
* settings, e.g., font size is the sum of descent and ascent. This is to provide as much convenience measures for type
* setting/font rendering as possible.
* Note: This class does not provide dpi awareness, which has to be handled outside of this class, e.g., during
* layouting and rendering.
*/
export class FontFace {

/** @see {@link base} */
protected _base: number;

/** @see {@link ascent} */
protected _ascent = 0.0;

/** @see {@link descent} */
protected _descent = 0.0;

/** @see {@link lineGap} */
protected _lineGap = 0.0;

/** @see {@link glyphTextureExtent} */
protected _glyphTextureExtent: GLfloat2 = [0.0, 0.0];

/** @see {@link glyphTexturePadding} */
protected _glyphTexturePadding: GLfloat4 = [0.0, 0.0, 0.0, 0.0];

/** @see {@link glyphTexturePadding} */
protected _glyphTexture: Texture2;

/**
* Map associating a glyph index to a glyph (sub image of a texture).
* @see {@link glyph}, @see {@link hasGlyph}, @see {@link addGlyph}
*/
protected _glyphs = new Map<GLsizei, Glyph>();

protected _context: Context;

/**
* Constructs an unconfigured, empty font face specification. The appropriate setters should be used for configuring
* the font face. Alternatively, the font importer (@see {@link FontImporter}) provides the import of bitmap-font
* base configuration file ({@link http://www.angelcode.com/products/bmfont/}).
* @param context - Valid context to create the object for.
* @param identifier - Meaningful name for identification of this instances VAO and VBOs.
*/
constructor(context: Context, identifier?: string) {
this._context = context;
const gl = context.gl;

identifier = identifier !== undefined && identifier !== `` ? identifier : this.constructor.name;
this._glyphTexture = new Texture2(context, identifier + 'GlyphAtlas');
const internalFormat = Wizard.queryInternalTextureFormat(context, gl.RGBA, Wizard.Precision.byte);
this._glyphTexture.initialize(1, 1, internalFormat[0], gl.RGBA, internalFormat[1]);
}

/**
* The size of the font in pt. The font size is the measure from the tops of the tallest glyphs (ascenders) to the
* bottom of the lowest descenders in pt. It is derived via the sum of ascent and descent.
* @return - The font size in pt (ascent + descent).
*/
get size(): number {
/* Note: this._descent is usually negative. */
return this._ascent - this._descent;
}

/**
* Set the font's base in pt. The base is the distance from the baseline to the top of the line in pt.
* @param base - The distance from the baseline to the top of the line in pt.
*/
set base(base: number) {
assert(base > 0.0, 'base should be larger than zero.');
this._base = base;
}
get base(): number {
return this._base;
}

/**
* Set the font's ascent in pt. The ascent is the distance from the baseline to the tops of the tallest glyphs
* (ascenders) in pt.
* @param ascent - The distance from the baseline to the topmost ascenders in pt.
*/
set ascent(ascent: number) {
assert(ascent > 0.0, 'ascent should be larger than zero.');
this._ascent = ascent;
}
get ascent(): number {
return this._ascent;
}

/**
* Set the font's descent in pt. The descent is the distance from the baseline to the lowest descenders in pt.
* Please note that this value is usually negative (if the fonts lowest descenders are below the baseline).
* @param descent - The distance from the baseline to the lowest descenders in pt.
*/
set descent(descent: number) {
/* No assert here: there might be fonts with their lowest descender above baseline. */
// assert(descent < 0.f, ...);
this._descent = descent;
}
get descent(): number {
return this._descent;
}

/**
* Set the font's leading/linegap in pt. The leading is the distance from the lowest descenders to the topmost
* ascenders of a subsequent text line in pt.
* @param lineGap - The gap between two subsequent lines of text in pt.
*/
set lineGap(lineGap: number) {
this._lineGap = lineGap;
}
get lineGap(): number {
return this._lineGap;
}

/**
* Set the baseline-to-baseline distance in pt. Negative values will result in negative linegap. The line height is
* derived as follows: line_height = size + line_gap, or alternatively: line_height = size * line_space
* @param lineHeight - The line height (baseline-to-baseline distance) in pt.
*/
set lineHeight(lineHeight: number) {
this._lineGap = lineHeight - this.size;
}
get lineHeight(): number {
return this.size + this.lineGap;
}

/**
* Set the relative baseline-to-baseline distance w.r.t. the font's size. The line space is mapped to line gap as
* follows: line_gap = size * (line_space - 1). A space < 1.0 will result in a negative line gap.
* @param lineSpace - The relative baseline-to-baseline distance w.r.t. the font's size.
*/
set lineSpace(lineSpace: number) {
this._lineGap = this.size * (lineSpace - 1);
}
/**
* The relative baseline-to-baseline distance w.r.t. the font's size. The relative line space is derived as follows:
* line_space = size / line_height; Note that the descent is usually a negative value.
* @return - The relative baseline-to-baseline distance w.r.t. the font's size.
*/
get lineSpace(): number {
if (this.lineHeight === 0.0) {
return this.lineHeight;
}
return this.size / this.lineHeight;
}

/**
* Sets the glyph texture atlas extent.
* @param extent - The texture extent in px
*/
set glyphTextureExtent(extent: GLsizei2) {
assert(extent[0] > 0, 'expected extent.x to be larger than zero.');
assert(extent[1] > 0, 'expected extent.y to be larger than zero.');
this._glyphTextureExtent = extent;
}
/**
* The size/extent of the glyph texture in px.
* @return - The size/extent of the glyph texture in px.
*/
get glyphTextureExtent(): GLsizei2 {
return this._glyphTextureExtent;
}

/**
* The padding applied to every glyph in px. This can only be set via setGlyphTexture.
* @param padding - CSS style (top, right, bottom, left) padding applied to every glyph within the texture in px.
*/
set glyphTexturePadding(padding: GLfloat4) {
assert(padding[0] >= 0.0, 'expected padding[0] to be larger than zero.');
assert(padding[1] >= 0.0, 'expected padding[1] to be larger than zero.');
assert(padding[2] >= 0.0, 'expected padding[2] to be larger than zero.');
assert(padding[3] >= 0.0, 'expected padding[3] to be larger than zero.');
this._glyphTexturePadding = padding;
}
get glyphTexturePadding(): GLfloat4 {
return this._glyphTexturePadding;
}

/**
* The font face's associated glyph atlas. All glyph data is associated to this texture atlas.
* @param texture - The new texture atlas for all glyphs
*/
set glyphTexture(texture: Texture2) {
this._glyphTexture = texture;
}
get glyphTexture(): Texture2 {
return this._glyphTexture;
}

/**
* Check if a glyph of a specific index is available.
* @return - True if a glyph for the provided index was added.
*/
hasGlyph(index: GLsizei): boolean {
return !!this._glyphs.get(index);
}

/**
* Direct access to an indexed glyph. If the glyph does not exist, an empty glyph is returned without adding it to
* glyphs. The glyph atlas might be loaded asynchronously, thus, new glyphs are expected to be added via addGlyph.
* @param index - Index of the glyph to access.
* @return - Glyph with the matching index or an empty glyph, if index has not match
*/
glyph(index: GLsizei): Glyph {
const existingGlyph = this._glyphs.get(index);
if (existingGlyph) {
return existingGlyph;
}
const glyph = new Glyph();
glyph.index = index;
return glyph;
}

/**
* Add a glyph to the font face's set of glyphs. If the glyph already exists, the existing glyph remains.
* @param glyph - The glyph to add to the set of glyphs.
*/
addGlyph(glyph: Glyph): void {
assert(!(this._glyphs.get(glyph.index)), 'expected glyph to not already exist');
this._glyphs.set(glyph.index, glyph);
}

/**
* Generates aan array of all comprised glyph indices.
* @return - An array of all glyph indices available to this font face.
*/
arrayOfGlyphIndices(): Array<GLsizei> {
return Array.from(this._glyphs.keys());
}

/**
* Check if a glyph is depictable/renderable. If the glyph's sub-texture vertical or horizontal extent is zero the
* glyph does not need to be depicted/rendered. E.g., spaces, line feeds, other control sequences as well as
* unknown glyphs do not need to be processed for rendering.
* @param index - Index of the glyph to access.
* @return - Returns true if the glyph needs to be depicted/rendered.
*/
depictable(index: GLsizei): boolean {
return this.glyph(index).depictable();
}

/**
* Kerning for a glyph and a subsequent glyph in pt. If the glyph or the subsequent glyph are unknown to this font
* face (assertion), 0.f will be returned. For more details on kerning, refer to the Glyph class.
* @param index - The current glyph index (e.g., of the current pen-position).
* @param subsequentIndex - The glyph index of the subsequent/next glyph.
* @return - The kerning (usually negative) between the two glyphs in pt. If either on of the glyphs is unknown to
* this font face or no specific kerning for the glyph pair is available a zero kerning is returned.
*/
kerning(index: GLsizei, subsequentIndex: GLsizei): number {
const glyph = this._glyphs.get(index);
if (!glyph) {
return 0.0;
}
return glyph.kerning(subsequentIndex);
}

/**
* Set the kerning for a glyph w.r.t. to a subsequent glyph in pt. If the glyph is known to this font face, the
* values are forwarded to the glyphs kerning setter (see Glyph for more information).
* @param index - The target glyph index.
* @param subsequentIndex - The glyph index of the respective subsequent/next glyph.
* @param kerning - Kerning of the two glyphs in pt.
*/
setKerning(index: GLsizei, subsequentIndex: GLsizei, kerning: number): void {
const glyph = this._glyphs.get(index);
if (!glyph || !this.hasGlyph(subsequentIndex)) {
assert(false, 'expected glyph or glyph of subsequent index to exist.');
return;
}
glyph.setKerning(subsequentIndex, kerning);
}

}
Loading