Skip to content

Commit

Permalink
- New Highlight tree extension optimizations
Browse files Browse the repository at this point in the history
- Cache for asciidoctor extensions
  • Loading branch information
rahmanusta committed Mar 16, 2015
1 parent e7b09cf commit f26f83c
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 117 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/kodcu/controller/ApplicationController.java
Expand Up @@ -363,8 +363,8 @@ private void convertEpub(boolean askPath) {
epub3Service.produceEpub3(askPath);
}

public String appendFormula(String fileName, String formula) {
return mathJaxService.appendFormula(fileName, formula);
public void appendFormula(String fileName, String formula) {
mathJaxService.appendFormula(fileName, formula);
}

public void svgToPng(String fileName, String svg, String formula, float width, float height) {
Expand Down Expand Up @@ -424,10 +424,10 @@ public void createFileTree(String tree, String type, String fileName, String wid
});
}

public void createFileTreee(String tree, String type, String fileName, String width, String height) {
public void createHighlightFileTree(String tree, String type, String fileName, String width, String height) {

threadService.runTaskLater(() -> {
treeService.createFileTreee(tree, type, fileName, width, height);
treeService.createHighlightFileTree(tree, type, fileName, width, height);
});
}

Expand Down
11 changes: 3 additions & 8 deletions src/main/java/com/kodcu/service/extension/MathJaxService.java
Expand Up @@ -41,13 +41,8 @@ public MathJaxService(final ApplicationController controller, final Current curr
this.current = current;
}

public String appendFormula(String fileName, String formula) {
if (fileName.endsWith(".png") || fileName.endsWith(".svg")) {
getWindow().call("appendFormula", new Object[] { fileName, formula });
return "images/" + fileName;
}

return "";
public void appendFormula(String fileName, String formula) {
getWindow().call("appendFormula", new Object[]{fileName, formula});
}

public JSObject getWindow() {
Expand Down Expand Up @@ -97,7 +92,7 @@ private void saveAsSvg(String fileName, String svg, String formula, float width,

private void saveAsPng(String fileName, String svg, String formula, float width, float height) {
try (StringReader reader = new StringReader(svg);
ByteArrayOutputStream ostream = new ByteArrayOutputStream();) {
ByteArrayOutputStream ostream = new ByteArrayOutputStream();) {

String uri = "http://www.w3.org/2000/svg";
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(XMLResourceDescriptor.getXMLParserClassName());
Expand Down
52 changes: 40 additions & 12 deletions src/main/java/com/kodcu/service/extension/TreeService.java
Expand Up @@ -201,7 +201,7 @@ public void createFileTree(String tree, String type, String fileName, String wid
}
}

public void createFileTreee(String tree, String type, String fileName, String width, String height) {
public void createHighlightFileTree(String tree, String type, String fileName, String width, String height) {
Objects.requireNonNull(fileName);

if (!fileName.endsWith(".png"))
Expand All @@ -221,12 +221,35 @@ public void createFileTreee(String tree, String type, String fileName, String wi
threadService.runActionLater(() -> {

WebView treeview = new WebView();
treeview.setMaxHeight(2500);
treeview.setMaxWidth(2500);
treeview.setPrefWidth(2500);
treeview.setPrefHeight(2500);
treeview.setMaxHeight(5000);
treeview.setMaxWidth(5000);
treeview.setPrefWidth(5000);
treeview.setPrefHeight(5000);
treeview.setLayoutX(-89999);
treeview.setLayoutY(-89999);

try {
Double value = Double.valueOf(width);

if (width.contains("+") || width.contains("-"))
treeview.setPrefWidth(treeview.getPrefWidth() + value);
else
treeview.setPrefWidth(value);
} catch (Exception e) {
logger.info(e.getMessage(), e);
}

try {
Double value = Double.valueOf(height);

if (height.contains("+") || height.contains("-"))
treeview.setPrefHeight(treeview.getPrefHeight() + value);
else
treeview.setPrefHeight(value);
} catch (Exception e) {
logger.info(e.getMessage(), e);
}

treeview.getEngine().load(String.format("http://localhost:%d/treeview.html", controller.getPort()));
controller.getRootAnchor().getChildren().add(treeview);

Expand All @@ -239,13 +262,18 @@ public void createFileTreee(String tree, String type, String fileName, String wi

WritableImage writableImage = treeview.snapshot(new SnapshotParameters(), null);
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(writableImage, null);
TrimWhite trimWhite = new TrimWhite();
BufferedImage trimmed = trimWhite.trim(bufferedImage);
IOHelper.createDirectories(path.resolve("images"));
IOHelper.imageWrite(trimmed, "png", treePath.toFile());
controller.getLastRenderedChangeListener()
.changed(null, controller.getLastRendered().getValue(), controller.getLastRendered().getValue());
controller.getRootAnchor().getChildren().remove(treeview);

threadService.runTaskLater(()->{
TrimWhite trimWhite = new TrimWhite();
BufferedImage trimmed = trimWhite.trim(bufferedImage);
IOHelper.createDirectories(path.resolve("images"));
IOHelper.imageWrite(trimmed, "png", treePath.toFile());
threadService.runActionLater(()->{
controller.getLastRenderedChangeListener()
.changed(null, controller.getLastRendered().getValue(), controller.getLastRendered().getValue());
controller.getRootAnchor().getChildren().remove(treeview);
});
});

}
});
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/kodcu/service/ui/WebviewService.java
Expand Up @@ -109,7 +109,7 @@ public WebView createWebView() {
if (Files.isDirectory(path)) {

StringBuffer buffer = new StringBuffer();
buffer.append("[treee,file=\"\"]");
buffer.append("[tree,file=\"\"]");
buffer.append("\n--\n");
buffer.append(asciiTreeGenerator.generate(path));
buffer.append("\n--");
Expand Down
24 changes: 18 additions & 6 deletions src/main/resources/public/js/asciidoctor-math-block.js
Expand Up @@ -22,7 +22,7 @@
self.$parse_content_as("simple");

return (def.$process = function (parent, reader, attrs) {
var self = this, content = nil, title = nil, filename = nil, alt=nil, caption = nil,width=nil,height=nil,scale=nil,align=nil;
var self = this, content = nil, title = nil, filename = nil, alt = nil, caption = nil, width = nil, height = nil, scale = nil, align = nil, cache = nil;

title = "" + (attrs['$[]']("title"));
alt = "" + (attrs['$[]']("alt"));
Expand All @@ -32,8 +32,12 @@
scale = "" + (attrs['$[]']("scale"));
align = "" + (attrs['$[]']("align"));
filename = "" + (attrs['$[]']("file"));
cache = "" + (attrs['$[]']("cache"));

content = app.appendFormula(filename, reader.$read());
if (cache != "enabled") {
app.appendFormula(filename, reader.$read());
}
content = "images/" + filename;

var attributesHash = {
"target": content,
Expand All @@ -48,8 +52,8 @@

var keys = Object.keys(attributesHash);

keys.forEach(function(key){
if(attributesHash[key]=="")
keys.forEach(function (key) {
if (attributesHash[key] == "")
delete attributesHash[key];
});

Expand All @@ -64,9 +68,17 @@
if ($scope.RUBY_ENGINE['$==']("opal")) {
}
;
return ($a = ($b = $scope.Extensions).$register, $a._p = (TMP_1 = function () {
return ($a = ($b = $scope.Extensions).$register, $a
.
_p = (TMP_1 = function () {
var self = TMP_1._s || this;

return self.$block($scope.MathBlock)
}, TMP_1._s = self, TMP_1), $a).call($b);
}, TMP_1
.
_s = self, TMP_1
),
$a
).
call($b);
})(Opal);
26 changes: 20 additions & 6 deletions src/main/resources/public/js/asciidoctor-tree-block.js
Expand Up @@ -22,7 +22,7 @@
self.$parse_content_as("literal");

return (def.$process = function (parent, reader, attrs) {
var $a, self = this, content = nil, type = nil, title = nil, filename = nil, alt = nil, caption = nil, width = nil, height = nil, scale = nil, align = nil;
var $a, self = this, content = nil, type = nil, title = nil, filename = nil, alt = nil, caption = nil, width = nil, height = nil, scale = nil, align = nil, cache = nil;

type = "" + (attrs['$[]']("type"));
title = "" + (attrs['$[]']("title"));
Expand All @@ -33,8 +33,14 @@
height = "" + (attrs['$[]']("height"));
scale = "" + (attrs['$[]']("scale"));
align = "" + (attrs['$[]']("align"));
cache = "" + (attrs['$[]']("cache"));

app.createFileTree(reader.$read(), type, filename, width, height);
if (cache != "enabled") {
if (type == "basic" || type == "old")
app.createFileTree(reader.$read(), type, filename, width, height);
else
app.createHighlightFileTree(reader.$read(), type, filename, width, height);
}

content = "images/" + filename;

Expand All @@ -51,8 +57,8 @@

var keys = Object.keys(attributesHash);

keys.forEach(function(key){
if(attributesHash[key]=="")
keys.forEach(function (key) {
if (attributesHash[key] == "")
delete attributesHash[key];
});

Expand All @@ -69,9 +75,17 @@
if ($scope.RUBY_ENGINE['$==']("opal")) {
}
;
return ($a = ($b = $scope.Extensions).$register, $a._p = (TMP_1 = function () {
return ($a = ($b = $scope.Extensions).$register, $a
.
_p = (TMP_1 = function () {
var self = TMP_1._s || this;

return self.$block($scope.TreeBlock)
}, TMP_1._s = self, TMP_1), $a).call($b);
}, TMP_1
.
_s = self, TMP_1
),
$a
).
call($b);
})(Opal);
77 changes: 0 additions & 77 deletions src/main/resources/public/js/asciidoctor-treee-block.js

This file was deleted.

8 changes: 6 additions & 2 deletions src/main/resources/public/js/asciidoctor-uml-block.js
Expand Up @@ -22,7 +22,7 @@
self.$parse_content_as("literal");

return (def.$process = function (parent, reader, attrs) {
var $a, self = this, content = nil, type = nil, title = nil, filename = nil, alt = nil, caption = nil,width=nil,height=nil,scale=nil,align=nil;
var $a, self = this, content = nil, type = nil, title = nil, filename = nil, alt = nil, caption = nil,width=nil,height=nil,scale=nil,align=nil,cache=nil;

title = "" + (attrs['$[]']("title"));
alt = "" + (attrs['$[]']("alt"));
Expand All @@ -33,8 +33,12 @@
align = "" + (attrs['$[]']("align"));
type = "" + (attrs['$[]']("type"));
filename = "" + (attrs['$[]']("file"));
cache = "" + (attrs['$[]']("cache"));

if (cache != "enabled"){
app.plantUml(reader.$read(), type, filename);
}

app.plantUml(reader.$read(), type, filename);

content = "images/" + filename;

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/public/preview.html
Expand Up @@ -23,7 +23,6 @@
<script src="/js/asciidoctor-uml-block.js"></script>
<script src="/js/asciidoctor-math-block.js"></script>
<script src="/js/asciidoctor-tree-block.js"></script>
<script src="/js/asciidoctor-treee-block.js"></script>
<script src="/js/asciidoctor-docbook.js"></script>

<script src="/js/jquery.js"></script>
Expand Down

0 comments on commit f26f83c

Please sign in to comment.