Skip to content

Commit

Permalink
Fixes handling of @# syntax in texts.
Browse files Browse the repository at this point in the history
  • Loading branch information
kortenkamp committed Jun 19, 2023
1 parent f25daf4 commit 4654caf
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
56 changes: 56 additions & 0 deletions examples/166_coords_in_text.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>Konstruktion.cdy</title>
<style type="text/css">
* {
margin: 0px;
padding: 0px;
}

#CSConsole {
background-color: #FAFAFA;
border-top: 1px solid #333333;
bottom: 0px;
height: 200px;
overflow-y: scroll;
position: fixed;
width: 100%;
}
</style>
<link rel="stylesheet" href="../build/js/CindyJS.css" />
<script type="text/javascript" src="../build/js/Cindy.js"></script>
<script type="text/javascript">
var cdy = CindyJS({
scripts: "cs*",
defaultAppearance: {
dimDependent: 0.7,
fontFamily: "sans-serif",
lineSize: 1,
pointSize: 5.0,
textsize: 12.0
},
angleUnit: "°",
geometry: [
{name: "A", type: "Free", pos: [-2.522522522522522, -4.0, -0.9009009009009008], color: [1.0, 0.0, 0.0], labeled: true},
{name: "Text0", type: "Text", pos: [4.88, 3.68, 1.0], color: [0.0, 0.0, 0.0], args: ["A"], text: "The coordinates of @$\"A\" are @#\"A\""}
],
ports: [{
id: "CSCanvas",
width: 680,
height: 336,
transform: [{visibleRect: [-9.06, 9.34, 18.14, -4.1]}],
background: "rgb(168,176,192)"
}],
csconsole: false,
use: ["katex"],
cinderella: {build: 2008, version: [3, 0, 2008]}
});
</script>
</head>
<body>
<div id="CSCanvas"></div>
</body>
</html>
10 changes: 6 additions & 4 deletions src/js/libgeo/GeoRender.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { CSNumber } from "libcs/CSNumber";
import { List } from "libcs/List";
import { General } from "libcs/General";
import { eval_helper, evaluator, niceprint } from "libcs/Essentials";
import { Accessor } from "libcs/Accessors";
import { textRendererHtml } from "libcs/OpDrawing";
import { Render2D } from "libcs/Render2D";
import { csport } from "libgeo/GeoState";
Expand Down Expand Up @@ -245,17 +246,18 @@ function drawgeotext(el) {
let name, el2;
try {
name = JSON.parse(match.substring(2));
el2 = csgeo.csnames[name];
el2 = csgeo.csnames[name]; // this does not deliver the ctype of el2, as ctype is separate from elements.
if (!el2) return "?";
} catch (err) {
return "?";
}
switch (match.charAt(1)) {
case "$":
return el2.printname || name;
case "#":
if (el2.kind !== "V") return "?";
return niceprint(el2.value);
case "#": // I do not like this. I would prefer an oo-approach.
if (el2.kind === "P") return niceprint(Accessor.getField(el2, "xy"));
if (el2.kind == "V") return niceprint(el2.value);
return el2.value;
}
});
let htmlCallback = null;
Expand Down

0 comments on commit 4654caf

Please sign in to comment.