Skip to content

Commit

Permalink
规范化Markdown,使之支持自定义扩展语法
Browse files Browse the repository at this point in the history
  • Loading branch information
EB-wilson committed Oct 2, 2024
1 parent 5a0ae32 commit a0f673d
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 28 deletions.
Binary file modified desktop9/build/libs/desktop9.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package universecore.ui.elements.markdown;

import java.util.ArrayList;
import java.util.List;

public class HighlightMatcher {
private List<LanguageHighlight> languages = new ArrayList<>();



public interface LanguageHighlight{
List<String> splitTokens(String text);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import arc.graphics.Color;
import arc.graphics.g2d.Draw;
import arc.graphics.g2d.Font;
import arc.graphics.g2d.GlyphLayout;
import arc.graphics.g2d.FontCache;
import arc.scene.style.Drawable;
import arc.util.Align;
import arc.util.pooling.Pools;
Expand All @@ -16,6 +16,8 @@ public class DrawStr extends Markdown.DrawObj {
Color color;
Drawable drawable;

private FontCache cache;

//use get
DrawStr(){}

Expand All @@ -30,27 +32,45 @@ public static DrawStr get(Markdown owner, String str, Font font, Color color, fl
res.color = color;
res.drawable = background;

Font.FontData data = font.getData();
float lastScl = data.scaleX;
data.setScale(scl);
res.cache = font.newFontCache();
res.cache.setText(str,
0, 0,
0,
Align.topLeft,
false
);
data.setScale(lastScl);

return res;
}

@Override
protected void draw() {
//调试用文本锚点
//Fill.square(parent.x + offsetX, parent.y + parent.getHeight() + offsetY, 4, 45);
cache.tint(tmp1.set(color).mul(Draw.getColor()));
cache.setPosition(
parent.x + offsetX,
parent.y + parent.getHeight() + offsetY
);

if (drawable != null) {
tmp2.set(Draw.getColor());
GlyphLayout layout = GlyphLayout.obtain();
layout.setText(font, text, tmp1.set(color).mul(Draw.getColor()), 0, Align.topLeft, false);

drawable.draw(parent.x + offsetX - drawable.getLeftWidth(), parent.y + parent.getHeight() + offsetY - font.getLineHeight() - 2, layout.width + drawable.getLeftWidth() + drawable.getRightWidth(), font.getLineHeight() + 5);
layout.free();
drawable.draw(
parent.x + offsetX - drawable.getLeftWidth(),
parent.y + parent.getHeight() + offsetY - font.getLineHeight() - 2,
cache.getLayouts().first().width + drawable.getLeftWidth() + drawable.getRightWidth(),
font.getLineHeight() + 5
);

Draw.color(tmp2);
font.draw(text, parent.x + offsetX, parent.y + parent.getHeight() + offsetY, tmp1.set(color).mul(Draw.getColor()), scl, true, Align.topLeft);
}
else {
font.draw(text, parent.x + offsetX, parent.y + parent.getHeight() + offsetY, tmp1.set(color).mul(Draw.getColor()), scl, true, Align.topLeft);
}

cache.draw();
}

@Override
Expand Down
30 changes: 15 additions & 15 deletions scenes/build/publications/maven/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"component": {
"group": "com.github.EB-wilson.UniverseCore",
"module": "scenes",
"version": "2.1.1",
"version": "2.2.0",
"attributes": {
"org.gradle.status": "release"
}
Expand All @@ -25,13 +25,13 @@
},
"files": [
{
"name": "scenes-2.1.1.jar",
"url": "scenes-2.1.1.jar",
"size": 114651,
"sha512": "b77b858baa0be859fe46bb3f29b95f4aef6c4427d6a1bf72e00c49cf16c8baa084cd941902ab461f9dc7b39734b9d6f1a731f8ff8fd6dd3dcf8348baf9bc7129",
"sha256": "6265835eb952f4fd5366fabd29413d9a5e9ba2e53aa226aa4c8cc7be815a8e6a",
"sha1": "f18a7ba0e2c4cc6d425c3bdf26bd3d13c3f5be08",
"md5": "4eac311a754e7acbc25e9b4e2a862c2c"
"name": "scenes-2.2.0.jar",
"url": "scenes-2.2.0.jar",
"size": 124412,
"sha512": "f6525bfcf465e8188871c98c637887108711f6591db1ecdc7d12aa0dd510ef6747c88f5d4f8da52982166b529dc1d4973075da3562e53f360c9d753003519d1e",
"sha256": "0b5367821cc72d6fe2fef5d5390be121e2214175b510b01ad162a2561e19f813",
"sha1": "bd2bece6eaf6e99d54414a04cbf9c0a52f9ec0b7",
"md5": "2de226c774fb7553286c69d674890e7a"
}
]
},
Expand All @@ -46,13 +46,13 @@
},
"files": [
{
"name": "scenes-2.1.1.jar",
"url": "scenes-2.1.1.jar",
"size": 114651,
"sha512": "b77b858baa0be859fe46bb3f29b95f4aef6c4427d6a1bf72e00c49cf16c8baa084cd941902ab461f9dc7b39734b9d6f1a731f8ff8fd6dd3dcf8348baf9bc7129",
"sha256": "6265835eb952f4fd5366fabd29413d9a5e9ba2e53aa226aa4c8cc7be815a8e6a",
"sha1": "f18a7ba0e2c4cc6d425c3bdf26bd3d13c3f5be08",
"md5": "4eac311a754e7acbc25e9b4e2a862c2c"
"name": "scenes-2.2.0.jar",
"url": "scenes-2.2.0.jar",
"size": 124412,
"sha512": "f6525bfcf465e8188871c98c637887108711f6591db1ecdc7d12aa0dd510ef6747c88f5d4f8da52982166b529dc1d4973075da3562e53f360c9d753003519d1e",
"sha256": "0b5367821cc72d6fe2fef5d5390be121e2214175b510b01ad162a2561e19f813",
"sha1": "bd2bece6eaf6e99d54414a04cbf9c0a52f9ec0b7",
"md5": "2de226c774fb7553286c69d674890e7a"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion scenes/build/publications/maven/pom-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.EB-wilson.UniverseCore</groupId>
<artifactId>scenes</artifactId>
<version>2.1.1</version>
<version>2.2.0</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
<groupId>com.github.EB-wilson.UniverseCore</groupId>
<artifactId>scenes</artifactId>
<versioning>
<latest>2.1.1</latest>
<release>2.1.1</release>
<latest>2.2.0</latest>
<release>2.2.0</release>
<versions>
<version>2.1.1</version>
<version>2.2.0</version>
</versions>
<lastUpdated>20240617093702</lastUpdated>
<lastUpdated>20241002165350</lastUpdated>
</versioning>
</metadata>

0 comments on commit a0f673d

Please sign in to comment.