[DEV] update log interface
This commit is contained in:
parent
a69546fa61
commit
4fec39b2a8
@ -84,28 +84,28 @@ public class EsvgFont {
|
|||||||
* @return true : Parsing is OK
|
* @return true : Parsing is OK
|
||||||
*/
|
*/
|
||||||
public static EsvgFont load(final Uri uri) {
|
public static EsvgFont load(final Uri uri) {
|
||||||
EsvgFont font = new EsvgFont();
|
final EsvgFont font = new EsvgFont();
|
||||||
XmlNode doc = null;
|
XmlNode doc = null;
|
||||||
try {
|
try {
|
||||||
doc = Exml.parse(uri);
|
doc = Exml.parse(uri);
|
||||||
} catch (ExmlException e) {
|
} catch (final ExmlException e) {
|
||||||
// TODO Auto-generated catch block
|
// TODO Auto-generated catch block
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!(doc instanceof XmlElement root)) {
|
if (!(doc instanceof final XmlElement root)) {
|
||||||
Log.error("can not load the SVG font ==> wrong root node");
|
Log.error("can not load the SVG font ==> wrong root node");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!root.existNode("svg") || !(root.getNodeNoExcept("svg") instanceof XmlElement svgNode)) {
|
if (!root.existNode("svg") || !(root.getNodeNoExcept("svg") instanceof final XmlElement svgNode)) {
|
||||||
Log.error("can not load Node <svg> in svg document");
|
Log.error("can not load Node <svg> in svg document");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!svgNode.existNode("defs") || !(svgNode.getNodeNoExcept("defs") instanceof XmlElement defsNode)) {
|
if (!svgNode.existNode("defs") || !(svgNode.getNodeNoExcept("defs") instanceof final XmlElement defsNode)) {
|
||||||
Log.error("can not load Node <defs> in svg document");
|
Log.error("can not load Node <defs> in svg document");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!defsNode.existNode("font") || !(defsNode.getNodeNoExcept("font") instanceof XmlElement fontElement)) {
|
if (!defsNode.existNode("font") || !(defsNode.getNodeNoExcept("font") instanceof final XmlElement fontElement)) {
|
||||||
Log.error("can not load Node <font> in svg document");
|
Log.error("can not load Node <font> in svg document");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -113,9 +113,9 @@ public class EsvgFont {
|
|||||||
font.horizAdvX = Integer.parseInt(fontElement.getAttribute("horiz-adv-x", "100"));
|
font.horizAdvX = Integer.parseInt(fontElement.getAttribute("horiz-adv-x", "100"));
|
||||||
|
|
||||||
int nbGlyph = 0;
|
int nbGlyph = 0;
|
||||||
for (XmlNode values : fontElement.getNodes()) {
|
for (final XmlNode values : fontElement.getNodes()) {
|
||||||
if (values.getValue().equals("font-face")) {
|
if (values.getValue().equals("font-face")) {
|
||||||
if (values instanceof XmlElement fontFace) {
|
if (values instanceof final XmlElement fontFace) {
|
||||||
font.fontFamily = fontFace.getAttribute("font-family", "unknown");
|
font.fontFamily = fontFace.getAttribute("font-family", "unknown");
|
||||||
font.fontStretch = fontFace.getAttribute("font-stretch", "normal");
|
font.fontStretch = fontFace.getAttribute("font-stretch", "normal");
|
||||||
font.fontWeight = Integer.parseInt(fontFace.getAttribute("font-weight", "400"));
|
font.fontWeight = Integer.parseInt(fontFace.getAttribute("font-weight", "400"));
|
||||||
@ -143,17 +143,17 @@ public class EsvgFont {
|
|||||||
//unicode-range="U+0020-1F093"
|
//unicode-range="U+0020-1F093"
|
||||||
tmp = fontFace.getAttribute("unicode-range", null);
|
tmp = fontFace.getAttribute("unicode-range", null);
|
||||||
tmpSplit = tmp.split("-");
|
tmpSplit = tmp.split("-");
|
||||||
int start = Integer.parseInt(tmpSplit[0].substring(2), 16);
|
final int start = Integer.parseInt(tmpSplit[0].substring(2), 16);
|
||||||
int stop = Integer.parseInt(tmpSplit[1], 16);
|
final int stop = Integer.parseInt(tmpSplit[1], 16);
|
||||||
font.unicodeRange = new Pair<>(start, stop);
|
font.unicodeRange = new Pair<>(start, stop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (XmlNode values : fontElement.getNodes()) {
|
for (final XmlNode values : fontElement.getNodes()) {
|
||||||
if (values.getValue().equals("glyph")) {
|
if (values.getValue().equals("glyph")) {
|
||||||
nbGlyph++;
|
nbGlyph++;
|
||||||
//Log.info("find flyph: " + nbGlyph);
|
//Log.info("find flyph: " + nbGlyph);
|
||||||
Glyph tmp = Glyph.valueOf(values.toElement(), font);
|
final Glyph tmp = Glyph.valueOf(values.toElement(), font);
|
||||||
if (tmp != null) {
|
if (tmp != null) {
|
||||||
font.glyphs.put(tmp.getUnicodeValue(), tmp);
|
font.glyphs.put(tmp.getUnicodeValue(), tmp);
|
||||||
}
|
}
|
||||||
@ -167,24 +167,24 @@ public class EsvgFont {
|
|||||||
Log.warning("unsupported node name :" + values.getValue());
|
Log.warning("unsupported node name :" + values.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (XmlNode values : fontElement.getNodes()) {
|
for (final XmlNode values : fontElement.getNodes()) {
|
||||||
if (values.getValue().equals("hkern")) {
|
if (values.getValue().equals("hkern")) {
|
||||||
if (values instanceof XmlElement kernElem) {
|
if (values instanceof final XmlElement kernElem) {
|
||||||
String g1 = kernElem.getAttribute("g1", null);
|
final String g1 = kernElem.getAttribute("g1", null);
|
||||||
String g2 = kernElem.getAttribute("g2", null);
|
final String g2 = kernElem.getAttribute("g2", null);
|
||||||
if (g1 == null || g2 == null) {
|
if (g1 == null || g2 == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
float offset = Float.parseFloat(kernElem.getAttribute("k", "0"));
|
final float offset = Float.parseFloat(kernElem.getAttribute("k", "0"));
|
||||||
if (offset == 0.0f) {
|
if (offset == 0.0f) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String[] g1Splited = g1.split(",");
|
final String[] g1Splited = g1.split(",");
|
||||||
String[] g2Splited = g2.split(",");
|
final String[] g2Splited = g2.split(",");
|
||||||
// create the list of kerning of the next elements
|
// create the list of kerning of the next elements
|
||||||
List<Kerning> elementsKerning = new ArrayList<>();
|
final List<Kerning> elementsKerning = new ArrayList<>();
|
||||||
for (int iii = 0; iii < g2Splited.length; iii++) {
|
for (int iii = 0; iii < g2Splited.length; iii++) {
|
||||||
for (Map.Entry<Integer, Glyph> entry : font.glyphs.entrySet()) {
|
for (final Map.Entry<Integer, Glyph> entry : font.glyphs.entrySet()) {
|
||||||
if (entry.getValue().getName().equals(g2Splited[iii])) {
|
if (entry.getValue().getName().equals(g2Splited[iii])) {
|
||||||
elementsKerning.add(new Kerning(offset, entry.getKey()));
|
elementsKerning.add(new Kerning(offset, entry.getKey()));
|
||||||
break;
|
break;
|
||||||
@ -193,7 +193,7 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
// add it on the
|
// add it on the
|
||||||
for (int iii = 0; iii < g1Splited.length; iii++) {
|
for (int iii = 0; iii < g1Splited.length; iii++) {
|
||||||
for (Map.Entry<Integer, Glyph> entry : font.glyphs.entrySet()) {
|
for (final Map.Entry<Integer, Glyph> entry : font.glyphs.entrySet()) {
|
||||||
if (entry.getValue().getName().equals(g1Splited[iii])) {
|
if (entry.getValue().getName().equals(g1Splited[iii])) {
|
||||||
entry.getValue().addKerning(elementsKerning);
|
entry.getValue().addKerning(elementsKerning);
|
||||||
font.hasKerning = true;
|
font.hasKerning = true;
|
||||||
@ -246,21 +246,21 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Vector2f calculateRenderOffset(final int fontSize) {
|
public Vector2f calculateRenderOffset(final int fontSize) {
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
float deltaY = realSize * this.ascent / this.unitsPerEm;
|
final float deltaY = realSize * this.ascent / this.unitsPerEm;
|
||||||
return new Vector2f(0, deltaY);
|
return new Vector2f(0, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float calculateSclaleFactor(final int fontSize) {
|
public float calculateSclaleFactor(final int fontSize) {
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
return (float) realSize / (float) this.unitsPerEm;
|
return (float) realSize / (float) this.unitsPerEm;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vector2i calculateTextSize(final int fontSize, final String data) {
|
public Vector2i calculateTextSize(final int fontSize, final String data) {
|
||||||
boolean withKerning = true;
|
final boolean withKerning = true;
|
||||||
int widthOut = calculateWidth(data, fontSize, withKerning);
|
final int widthOut = calculateWidth(data, fontSize, withKerning);
|
||||||
|
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
return new Vector2i(widthOut, realSize);
|
return new Vector2i(widthOut, realSize);
|
||||||
/*
|
/*
|
||||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
float scale = (float) realSize / (float) this.unitsPerEm;
|
||||||
@ -287,12 +287,12 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int calculateWidth(final int uVal, final int fontSize) {
|
public int calculateWidth(final int uVal, final int fontSize) {
|
||||||
Glyph glyph = getGlyph(uVal);
|
final Glyph glyph = getGlyph(uVal);
|
||||||
if (glyph == null) {
|
if (glyph == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
final float scale = (float) realSize / (float) this.unitsPerEm;
|
||||||
return (int) (glyph.getHorizAdvX() * scale);
|
return (int) (glyph.getHorizAdvX() * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,13 +301,13 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int calculateWidth(final String data, final int fontSize, final boolean withKerning) {
|
public int calculateWidth(final String data, final int fontSize, final boolean withKerning) {
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
final float scale = (float) realSize / (float) this.unitsPerEm;
|
||||||
//Log.error("scale =" + scale+ " font size = " + fontSize + " realSize=" + realSize);
|
//Log.error("scale =" + scale+ " font size = " + fontSize + " realSize=" + realSize);
|
||||||
float offsetWriting = 0;
|
float offsetWriting = 0;
|
||||||
int lastValue = 0;
|
int lastValue = 0;
|
||||||
for (char uVal : data.toCharArray()) {
|
for (final char uVal : data.toCharArray()) {
|
||||||
Glyph glyph = getGlyph(uVal);
|
final Glyph glyph = getGlyph(uVal);
|
||||||
if (glyph == null) {
|
if (glyph == null) {
|
||||||
lastValue = uVal;
|
lastValue = uVal;
|
||||||
continue;
|
continue;
|
||||||
@ -317,7 +317,7 @@ public class EsvgFont {
|
|||||||
lastValue = uVal;
|
lastValue = uVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
float advenceXLocal = glyph.getHorizAdvX() * scale;
|
final float advenceXLocal = glyph.getHorizAdvX() * scale;
|
||||||
offsetWriting += advenceXLocal;
|
offsetWriting += advenceXLocal;
|
||||||
//Log.error("offset X =" + offsetWriting + " + " + advenceXLocal + " " + uVal);
|
//Log.error("offset X =" + offsetWriting + " + " + advenceXLocal + " " + uVal);
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Glyph getGlyph(final int glyphIndex) {
|
public Glyph getGlyph(final int glyphIndex) {
|
||||||
Glyph out = this.glyphs.get(glyphIndex);
|
final Glyph out = this.glyphs.get(glyphIndex);
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
return this.missingGlyph;
|
return this.missingGlyph;
|
||||||
}
|
}
|
||||||
@ -347,7 +347,7 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Glyph getGlyphNullIfMissing(final int glyphIndex) {
|
public Glyph getGlyphNullIfMissing(final int glyphIndex) {
|
||||||
Glyph out = this.glyphs.get(glyphIndex);
|
final Glyph out = this.glyphs.get(glyphIndex);
|
||||||
if (out == null) {
|
if (out == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -379,19 +379,19 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Weight render(final int uVal, final int fontSize) {
|
public Weight render(final int uVal, final int fontSize) {
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
Glyph glyph = getGlyph(uVal);
|
final Glyph glyph = getGlyph(uVal);
|
||||||
if (glyph == null) {
|
if (glyph == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
final float scale = (float) realSize / (float) this.unitsPerEm;
|
||||||
RenderingConfig config = new RenderingConfig(10, 0.25f, 8);
|
final RenderingConfig config = new RenderingConfig(10, 0.25f, 8);
|
||||||
Matrix2x3f transform = Matrix2x3f.createTranslate(new Vector2f(0, -this.descent)).multiply(Matrix2x3f.createScale(scale));
|
final Matrix2x3f transform = Matrix2x3f.createTranslate(new Vector2f(0, -this.descent)).multiply(Matrix2x3f.createScale(scale));
|
||||||
PathModel model = glyph.getModel();
|
final PathModel model = glyph.getModel();
|
||||||
if (model == null) {
|
if (model == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Weight data = glyph.getModel().drawFill(calculateWidthRendering(uVal, fontSize), transform, 8, config);
|
final Weight data = glyph.getModel().drawFill(calculateWidthRendering(uVal, fontSize), transform, 8, config);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,17 +400,17 @@ public class EsvgFont {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Weight render(final String data, final int fontSize, final boolean withKerning) {
|
public Weight render(final String data, final int fontSize, final boolean withKerning) {
|
||||||
int widthOut = calculateWidth(data, fontSize, withKerning);
|
final int widthOut = calculateWidth(data, fontSize, withKerning);
|
||||||
|
|
||||||
int realSize = calculateFontRealHeight(fontSize);
|
final int realSize = calculateFontRealHeight(fontSize);
|
||||||
float scale = (float) realSize / (float) this.unitsPerEm;
|
final float scale = (float) realSize / (float) this.unitsPerEm;
|
||||||
|
|
||||||
Weight weight = new Weight(new Vector2i(widthOut, realSize));
|
final Weight weight = new Weight(new Vector2i(widthOut, realSize));
|
||||||
|
|
||||||
float offsetWriting = 0;
|
float offsetWriting = 0;
|
||||||
int lastValue = 0;
|
int lastValue = 0;
|
||||||
for (char uVal : data.toCharArray()) {
|
for (final char uVal : data.toCharArray()) {
|
||||||
Glyph glyph = getGlyph(uVal);
|
final Glyph glyph = getGlyph(uVal);
|
||||||
if (glyph == null) {
|
if (glyph == null) {
|
||||||
lastValue = uVal;
|
lastValue = uVal;
|
||||||
continue;
|
continue;
|
||||||
@ -421,13 +421,13 @@ public class EsvgFont {
|
|||||||
lastValue = uVal;
|
lastValue = uVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
float advenceXLocal = glyph.getHorizAdvX() * scale;
|
final float advenceXLocal = glyph.getHorizAdvX() * scale;
|
||||||
|
|
||||||
RenderingConfig config = new RenderingConfig(10, 0.25f, 8);
|
final RenderingConfig config = new RenderingConfig(10, 0.25f, 8);
|
||||||
Matrix2x3f transform = Matrix2x3f.createTranslate(new Vector2f(0, -this.descent)).multiply(Matrix2x3f.createScale(scale));
|
final Matrix2x3f transform = Matrix2x3f.createTranslate(new Vector2f(0, -this.descent)).multiply(Matrix2x3f.createScale(scale));
|
||||||
PathModel model = glyph.getModel();
|
final PathModel model = glyph.getModel();
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
Weight redered = model.drawFill(calculateWidthRendering((int) uVal, fontSize), transform, 8, config);
|
final Weight redered = model.drawFill(calculateWidthRendering((int) uVal, fontSize), transform, 8, config);
|
||||||
weight.fusion(redered, (int) offsetWriting, 0);
|
weight.fusion(redered, (int) offsetWriting, 0);
|
||||||
}
|
}
|
||||||
offsetWriting += advenceXLocal;
|
offsetWriting += advenceXLocal;
|
||||||
|
@ -16,51 +16,58 @@ public class Log {
|
|||||||
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE);
|
private static final boolean PRINT_VERBOSE = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.VERBOSE);
|
||||||
private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING);
|
private static final boolean PRINT_WARNING = Logger.getNeedPrint(Log.LIB_NAME, LogLevel.WARNING);
|
||||||
|
|
||||||
public static void critical(final String data) {
|
public static void critical(final Exception e, final String data) {
|
||||||
if (Log.PRINT_CRITICAL || Log.FORCE_ALL) {
|
e.printStackTrace();
|
||||||
Logger.critical(Log.LIB_NAME_DRAW, data);
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
|
Logger.critical(LIB_NAME_DRAW, data + " : " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void debug(final String data) {
|
public static void critical(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_DEBUG || Log.FORCE_ALL) {
|
if (PRINT_CRITICAL || FORCE_ALL) {
|
||||||
Logger.debug(Log.LIB_NAME_DRAW, data);
|
Logger.critical(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void error(final String data) {
|
public static void debug(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_ERROR || Log.FORCE_ALL) {
|
if (PRINT_DEBUG || FORCE_ALL) {
|
||||||
Logger.error(Log.LIB_NAME_DRAW, data);
|
Logger.debug(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void info(final String data) {
|
public static void error(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_INFO || Log.FORCE_ALL) {
|
if (PRINT_ERROR || FORCE_ALL) {
|
||||||
Logger.info(Log.LIB_NAME_DRAW, data);
|
Logger.error(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void print(final String data) {
|
public static void info(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_PRINT || Log.FORCE_ALL) {
|
if (PRINT_INFO || FORCE_ALL) {
|
||||||
Logger.print(Log.LIB_NAME_DRAW, data);
|
Logger.info(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void todo(final String data) {
|
public static void print(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_TODO || Log.FORCE_ALL) {
|
if (PRINT_PRINT || FORCE_ALL) {
|
||||||
Logger.todo(Log.LIB_NAME_DRAW, data);
|
Logger.print(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void verbose(final String data) {
|
public static void todo(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_VERBOSE || Log.FORCE_ALL) {
|
if (PRINT_TODO || FORCE_ALL) {
|
||||||
Logger.verbose(Log.LIB_NAME_DRAW, data);
|
Logger.todo(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void warning(final String data) {
|
public static void verbose(final String data, final Object... objects) {
|
||||||
if (Log.PRINT_WARNING || Log.FORCE_ALL) {
|
if (PRINT_VERBOSE || FORCE_ALL) {
|
||||||
Logger.warning(Log.LIB_NAME_DRAW, data);
|
Logger.verbose(LIB_NAME_DRAW, data, objects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void warning(final String data, final Object... objects) {
|
||||||
|
if (PRINT_WARNING || FORCE_ALL) {
|
||||||
|
Logger.warning(LIB_NAME_DRAW, data, objects);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user