[DEV] add capabilities on font
This commit is contained in:
parent
6f57f68505
commit
0a7342c0ad
@ -256,6 +256,35 @@ public class EsvgFont {
|
||||
return (float) realSize / (float) this.unitsPerEm;
|
||||
}
|
||||
|
||||
public Vector2i calculateTextSize(final int fontSize, final String data) {
|
||||
boolean withKerning = true;
|
||||
int widthOut = calculateWidth(data, fontSize, withKerning);
|
||||
|
||||
int realSize = calculateFontRealHeight(fontSize);
|
||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
||||
|
||||
Weight weight = new Weight(new Vector2i(widthOut, realSize));
|
||||
|
||||
int offsetWriting = 0;
|
||||
int lastValue = 0;
|
||||
for (char uVal : data.toCharArray()) {
|
||||
Glyph glyph = getGlyph(uVal);
|
||||
if (glyph == null) {
|
||||
lastValue = uVal;
|
||||
continue;
|
||||
}
|
||||
if (withKerning) {
|
||||
offsetWriting -= glyph.getKerning(lastValue) * scale;
|
||||
lastValue = uVal;
|
||||
}
|
||||
|
||||
float advenceXLocal = glyph.getHorizAdvX() * scale;
|
||||
// No generation of output ...
|
||||
offsetWriting += advenceXLocal;
|
||||
}
|
||||
return new Vector2i(offsetWriting, realSize);
|
||||
}
|
||||
|
||||
public int calculateWidth(final int uVal, final int fontSize) {
|
||||
Glyph glyph = getGlyph(uVal);
|
||||
if (glyph == null) {
|
||||
|
@ -1,9 +1,11 @@
|
||||
package org.atriasoft.esvg;
|
||||
|
||||
import org.atriasoft.egami.ImageByteRGBA;
|
||||
import org.atriasoft.egami.ImageByte;
|
||||
import org.atriasoft.egami.ToolImage;
|
||||
import org.atriasoft.esvg.internal.Log;
|
||||
import org.atriasoft.esvg.render.PathModel;
|
||||
import org.atriasoft.etk.Color;
|
||||
import org.atriasoft.etk.Configs;
|
||||
import org.atriasoft.etk.math.Vector2f;
|
||||
import org.atriasoft.etk.math.Vector2i;
|
||||
|
||||
@ -13,7 +15,7 @@ import org.atriasoft.etk.math.Vector2i;
|
||||
*
|
||||
*/
|
||||
public class GraphicContext {
|
||||
private EsvgDocument document;
|
||||
private EsvgDocument document = new EsvgDocument();
|
||||
PaintState paintState;
|
||||
private PathModel path = null;
|
||||
private Vector2i size = Vector2i.VALUE_32;
|
||||
@ -22,6 +24,10 @@ public class GraphicContext {
|
||||
clear();
|
||||
}
|
||||
|
||||
public Vector2i calculateTextSize(final String data) {
|
||||
return FontCache.getFont(Configs.getConfigFonts().getName(), false, false).calculateTextSize(Configs.getConfigFonts().getSize(), data);
|
||||
}
|
||||
|
||||
public void circle(final Vector2f position, final float radius) {
|
||||
this.document.addElement(new Circle(position, radius, this.paintState.clone()));
|
||||
}
|
||||
@ -85,6 +91,14 @@ public class GraphicContext {
|
||||
return this.paintState.getStrokeWidth();
|
||||
}
|
||||
|
||||
public int getTextHeight() {
|
||||
return getTextHeight(Configs.getConfigFonts().getSize());
|
||||
}
|
||||
|
||||
public int getTextHeight(final float height) {
|
||||
return FontCache.getFont(Configs.getConfigFonts().getName(), false, false).calculateFontRealHeight((int) height);
|
||||
}
|
||||
|
||||
public void line(final Vector2f origin, final Vector2f destination) {
|
||||
this.document.addElement(new Line(origin, destination, this.paintState.clone()));
|
||||
}
|
||||
@ -181,12 +195,8 @@ public class GraphicContext {
|
||||
this.document.addElement(new Rectangle(position, width, this.paintState.clone()));
|
||||
}
|
||||
|
||||
public ImageByteRGBA render() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String renderSvg() {
|
||||
return null;
|
||||
public ImageByte render() {
|
||||
return ToolImage.convertImageByte(this.document.renderImageFloatRGBA(null));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,7 +259,10 @@ public class GraphicContext {
|
||||
|
||||
public void text(final Vector2f position, final float height, final String data) {
|
||||
this.document.addElement(new Text(position, height, data, this.paintState.clone()));
|
||||
}
|
||||
|
||||
public void text(final Vector2f position, final String data) {
|
||||
this.document.addElement(new Text(position, Configs.getConfigFonts().getSize(), data, this.paintState.clone()));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -131,6 +131,9 @@ public class Text extends Base {
|
||||
DynamicColor colorStroke = null;
|
||||
if (this.paint.strokeWidth > 0.0f) {
|
||||
colorStroke = DynamicColor.createColor(this.paint.stroke, mtx);
|
||||
if (colorStroke == null) {
|
||||
Log.warning("Color stroke is null: ...");
|
||||
} else {
|
||||
// check if we need to display stroke:
|
||||
SegmentList listSegmentStroke = new SegmentList();
|
||||
listSegmentStroke.createSegmentListStroke(listPoints, this.paint.strokeWidth, this.paint.lineCap, this.paint.lineJoin, this.paint.miterLimit);
|
||||
@ -139,6 +142,7 @@ public class Text extends Base {
|
||||
// now, traverse the scanlines and find the intersections on each scanline, use non-zero rule
|
||||
tmpStroke.generate(myRenderer.getSize(), myRenderer.getNumberSubScanLine(), listSegmentStroke);
|
||||
}
|
||||
}
|
||||
// add on images:
|
||||
myRenderer.print(tmpFill, colorFill, tmpStroke, colorStroke, this.paint.opacity);
|
||||
}
|
||||
|
127
test/Unnamed document 2.svg
Normal file
127
test/Unnamed document 2.svg
Normal file
@ -0,0 +1,127 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="300"
|
||||
height="300"
|
||||
viewBox="0 0 79.374998 79.375002"
|
||||
version="1.1"
|
||||
id="svg8"
|
||||
inkscape:version="1.0.2 (e86c870879, 2021-01-15, custom)"
|
||||
sodipodi:docname="Unnamed document 2.svg">
|
||||
<defs
|
||||
id="defs2" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="0.98994949"
|
||||
inkscape:cx="443.11885"
|
||||
inkscape:cy="483.15179"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
inkscape:document-rotation="0"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="3838"
|
||||
inkscape:window-height="2118"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="20"
|
||||
inkscape:window-maximized="1" />
|
||||
<metadata
|
||||
id="metadata5">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title></dc:title>
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.35px;line-height:1.25;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
|
||||
x="52.662182"
|
||||
y="11.725324"
|
||||
id="text835"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan833"
|
||||
x="52.662182"
|
||||
y="11.725324"
|
||||
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.35px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;stroke-width:0.264583">H<tspan
|
||||
style="fill:#d38b00;fill-opacity:1"
|
||||
id="tspan1023">e</tspan>llo</tspan><tspan
|
||||
sodipodi:role="line"
|
||||
x="52.662182"
|
||||
y="19.662823"
|
||||
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:6.35px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;stroke-width:0.264583"
|
||||
id="tspan847">sq<tspan
|
||||
style="fill:#8c0000;fill-opacity:1"
|
||||
id="tspan1029">m</tspan>l</tspan><tspan
|
||||
sodipodi:role="line"
|
||||
x="52.662182"
|
||||
y="27.600323"
|
||||
style="font-style:italic;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:6.35px;font-family:sans-serif;-inkscape-font-specification:'sans-serif, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;stroke-width:0.264583"
|
||||
id="tspan849">k<tspan
|
||||
style="fill:#000063;fill-opacity:1"
|
||||
id="tspan1031">s</tspan>d</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:5.64444444px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;-inkscape-font-specification:'sans-serif, Normal';font-stretch:normal;font-variant:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;"
|
||||
x="1.3595439"
|
||||
y="44.163139"
|
||||
id="text853"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan851"
|
||||
x="1.3595439"
|
||||
y="44.163139"
|
||||
style="stroke-width:0.264583;-inkscape-font-specification:'sans-serif, Normal';font-family:sans-serif;font-weight:normal;font-style:normal;font-stretch:normal;font-variant:normal;font-size:5.64444444px;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;">Hello</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:5.64444444px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;-inkscape-font-specification:'sans-serif, Normal';font-stretch:normal;font-variant:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;"
|
||||
x="1.1807559"
|
||||
y="55.513321"
|
||||
id="text857"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan855"
|
||||
x="1.1807559"
|
||||
y="55.513321"
|
||||
style="stroke-width:0.264583;font-weight:bold;-inkscape-font-specification:'sans-serif, Normal';font-family:sans-serif;font-style:normal;font-stretch:normal;font-variant:normal;font-size:5.64444444px;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">Hello Bold</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:5.64444444px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;-inkscape-font-specification:'sans-serif, Normal';font-stretch:normal;font-variant:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;"
|
||||
x="1.196579"
|
||||
y="65.77121"
|
||||
id="text861"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan859"
|
||||
x="1.196579"
|
||||
y="65.77121"
|
||||
style="stroke-width:0.264583;font-style:italic;-inkscape-font-specification:'sans-serif, Normal';font-family:sans-serif;font-weight:normal;font-stretch:normal;font-variant:normal;font-size:5.64444444px;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">Hello Italic</tspan></text>
|
||||
<text
|
||||
xml:space="preserve"
|
||||
style="font-style:normal;font-weight:normal;font-size:5.64444444px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583;-inkscape-font-specification:'sans-serif, Normal';font-stretch:normal;font-variant:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal;"
|
||||
x="1.9766912"
|
||||
y="76.594482"
|
||||
id="text865"><tspan
|
||||
sodipodi:role="line"
|
||||
id="tspan863"
|
||||
x="1.9766912"
|
||||
y="76.594482"
|
||||
style="stroke-width:0.264583;font-weight:bold;font-style:italic;-inkscape-font-specification:'sans-serif, Normal';font-family:sans-serif;font-stretch:normal;font-variant:normal;font-size:5.64444444px;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-east-asian:normal">Hello Bold Italic</tspan></text>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 7.4 KiB |
Loading…
x
Reference in New Issue
Block a user