Skip to content

Commit 7dbd030

Browse files
committed
improvement of modular structure. Still a lot of work to do
1 parent cdcc927 commit 7dbd030

File tree

7 files changed

+982
-26
lines changed

7 files changed

+982
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ nbproject
22
.vscode
33
node_modules
44
package-lock.json
5+
dist

js/README.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Rendering engine.
2+
3+
A note about the result:
4+
5+
We have decided to go for SVG as a rendering technique, as
6+
it will be more versatile in the end.
7+
8+
**TODO**
9+
attach to all MDC elements an *delegate* which will
10+
be in charge of all layout processing.
11+
12+
This will allow us to use inheritance when it's useful.
13+
14+
15+
## Vocabulary:
16+
17+
An element has two sets of geometrical infomations:
18+
INNER informations, expressed in the internal system of the element.
19+
`inner= {dim: {width: w, height: h}};`
20+
OUTER informations, which are expressed in the coordinate system of the PARENT element:
21+
`outer= {origin: {x:x, y:y}, dim: {width: w, height: h}};`
22+
23+
24+
packedSize
25+
: the size of the elements, if we completely pack their content.
26+
27+
28+
scale
29+
: from inner to outer.
30+
31+
There could be a INNER origin. We don't know if it's relevant.
32+
33+
34+
## Algorithm
35+
* add spaces where needed
36+
* pack
37+
* scale for max WIDTH
38+
* scale for max HEIGHT
39+
* perform layout ???? (not sure it's needed).
40+
* generate actual graphical representation.
41+
42+
the mdc structure will be decorated by the layout system.
43+
to avoid messing things, all added information will go
44+
in a `_layout` field.
45+
46+
layout information will be stored in the (...) **(write this!!!)**
47+
48+
## Strategy
49+
50+
We face a small problem here and there:
51+
when rescaling, we may change the layout of an element.
52+
Recomputing this layout is not that easy, in part because of spaces.
53+
54+
Instead of repetedly having to compute with those spaces,
55+
we have decided to represent them as elements.
56+
there will be hspaces, vspaces and qspaces, with minimal sizes and
57+
extensibility.
58+
59+
Except in the last pass of layout, we will consider them with their minimal
60+
extensibility.
61+
62+
63+
Difference between html layout and svg layout
64+
65+
html layout needs UNITS and uses different solutions:
66+
a) positioning for

js/jsesh.js

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ var MDC_PREFERENCES = {
3232

3333
let glyphsInfo = {};
3434

35-
36-
3735
function renderMdcObjectInto(mdcObject, targetElt, options) {
3836

3937
/**
@@ -141,7 +139,7 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
141139
height: elt.naturalHeight
142140
});
143141
};
144-
elt.src = hieroglyphicSource+ "/" + code + ".svg";
142+
elt.src = hieroglyphicSource + "/" + code + ".svg";
145143
});
146144
}
147145
}
@@ -314,7 +312,6 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
314312
return res;
315313
}
316314

317-
318315
let globalGeom = g.layout.getOuterGeometry();
319316

320317
const svgRoot = createElement("svg", {
@@ -323,6 +320,7 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
323320
height: (globalGeom.getHeight() + 2) * globalScale,
324321
xmlns: SVG_NS
325322
});
323+
326324
/**
327325
* Perform a transformation.
328326
* action is a function which takes an empty transform,
@@ -349,24 +347,23 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
349347
function scale(elt, scale) {
350348
doTransformAux(elt, base => base.setScale(scale, scale));
351349
}
352-
350+
353351

354352
function drawCartoucheAround(group) {
355-
353+
356354
var frame = createElement("svg:path", {
357355
//width: g.layout.inner.width,
358356
//height: g.layout.inner.height,
359357
//d: "m 0,-3 " + g.layout.inner.width + ", 0",
360-
d: "M 0,-4 h "+ group.layout.inner.width // top horizontal line
361-
+ " c 10,0 10,"+ (group.layout.inner.height + 8) + " 0,"+(group.layout.inner.height + 8)
362-
+ " h -"+ group.layout.inner.width
363-
+ " c -10, 0"+ " -10," + -(group.layout.inner.height + 8) + " 0,"+ -(group.layout.inner.height + 8)
358+
d: "M 0,-4 h " + group.layout.inner.width // top horizontal line
359+
+ " c 10,0 10," + (group.layout.inner.height + 8) + " 0," + (group.layout.inner.height + 8)
360+
+ " h -" + group.layout.inner.width
361+
+ " c -10, 0" + " -10," + -(group.layout.inner.height + 8) + " 0," + -(group.layout.inner.height + 8)
364362
+ " Z "
365-
+ "M "+ (group.layout.inner.width+8) + ",-4"
366-
+ " v "+ (group.layout.inner.height + 8)
363+
+ "M " + (group.layout.inner.width + 8) + ",-4"
364+
+ " v " + (group.layout.inner.height + 8)
367365
,
368-
369-
366+
370367
style: "fill: none; color:#000000;stroke:#000000;stroke-width:1"
371368
});
372369
return frame;
@@ -383,7 +380,7 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
383380
case 'space':
384381
return null;
385382
case 'lig': {
386-
let url = hieroglyphicSource+ "/" + g.aux.code + ".svg";
383+
let url = hieroglyphicSource + "/" + g.aux.code + ".svg";
387384
res = createElement("image", {
388385
href: url,
389386
width: g.layout.inner.width,
@@ -393,7 +390,7 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
393390
break;
394391
case 's':
395392
{
396-
let url = hieroglyphicSource+ "/" + g.code + ".svg";
393+
let url = hieroglyphicSource + "/" + g.code + ".svg";
397394
// Note : in svg 1.1, width and height are mandatory.
398395
// in svg 1.2, not.
399396
// Chrome can work without width and height, not safari
@@ -444,15 +441,15 @@ function renderMdcObjectInto(mdcObject, targetElt, options) {
444441
return null;
445442
}
446443
break;
447-
// In fact, we should have a much simpler rendering system :
448-
// cartouches would add a kind of frame...
449-
case 'cartouche':
450-
var res = createElement("g", {});
451-
res.appendChild(drawCartoucheAround(g));
452-
break;
444+
// In fact, we should have a much simpler rendering system :
445+
// cartouches would add a kind of frame...
446+
case 'cartouche':
447+
var res = createElement("g", {});
448+
res.appendChild(drawCartoucheAround(g));
449+
break;
453450
default:
454451
{
455-
var res = createElement("g", {});
452+
var res = createElement("g", {});
456453
}
457454
break;
458455
}
@@ -554,11 +551,11 @@ function buildMDCObject(mdcString) {
554551
return { type: 'symbol', code: "]" };
555552
break;
556553
default:
557-
throw "unknown code "+ tree.value;
554+
throw "unknown code " + tree.value;
558555
}
559556
break;
560557
default:
561-
throw "unknown code "+tree.value;
558+
throw "unknown code " + tree.value;
562559
}
563560
}
564561
let r = mdcParser.parse(mdcString);

0 commit comments

Comments
 (0)