Hello Tarquin,
i tweaked and fiddled around and now have a version that correctly
scales, rotates and aligns.
Your wiki page hint helped, but i already found it in the past... The
example code there does not work here for some reason (compile error).
But anyhow, to answer your question regarding the "0.001" rotation
parameter in the label calling:
if i use "0.0" or "0" or also "0.0001", it puts my label text in the
center of the generated map with rotation of the scrap-rotation applied.
I don't know why and found by try-and-error that this value works.
Here is the updated code:, enhanced with a nicer legend output:
---
# Symbol to denote assigned survey.
# Option "-attr text " shows given text; otherwise current
survey is shown.
# Option "-attr bordersmooth " overrides edge smoothness (0
for sharp edges)
# Option "-attr bordermargin " overrides margin text/border
# Option "-attr basescale " overrides basic text sizing
factor (default text size)
def p_u_mappe(expr pos, theta, sc, al) =
T:=identity aligned al rotated theta scaled sc shifted pos;
begingroup;
% Basic config
bordersmooth:=4; % smoothness of box corners (0=90°
edges)
bordermargin:=5.0bp; % padding border->text
basescale:=1.0; % basic scaling of default-sized text
if known(ATTR_bordersmooth):
bordersmooth:=scantokens(ATTR_bordersmooth); fi;
if known(ATTR_bordermargin):
bordermargin:=scantokens(ATTR_bordermargin); fi;
if known(ATTR_basescale):
basescale:=scantokens(ATTR_basescale); fi;
% GET LABEL TEXT:
string txt;
if known(ATTR_text):
txt := ATTR_text;
else:
txt := ATTR__survey;
fi;
% DRAW LABEL:
lab:=thelabel(txt, (0.0,0.0));
pickup PenA; % border thickness
interim bboxmargin:=bordermargin; % padding border->text
q:=((bbox lab) smoothed bordersmooth) aligned al scaled (sc *
basescale) rotated theta shifted pos;
draw q;
lab:=lab aligned al;
lab:=lab scaled (sc * basescale);
lab:=lab rotated theta;
lab:=lab shifted pos;
process_label(pos, 0.001); % for some weird reason "0.0" does
not work here and puts the label to map-center at scrap-rotation.
endgroup;
enddef;
def p_u_mappe_legend =
begingroup;
save ATTR_text;
string ATTR_text;
ATTR_text:="028";
p_u_mappe((.5,.5) inscale, 0, 1.0, (0,0));
endgroup;
enddef;
---
Am 2020-03-01 22:23, schrieb Tarquin Wilton-Jones via Therion:
thelabel(txt, pos);
I notice in the main Therion Metapost, it uses
lab:=thelabel@#(txt, pos);
to make sure that it can respect alignment, which your code cannot.
Don't suppose you worked out how to pass the correct alignment value
to
it, did you?
I have worked it out, see my thread "Metapost variable macro suffixes".
I will add it to my existing function which takes the point alignment
parameter and turns it into the right suffix in the "thelabel" call or
p_label call, whichever one ends up getting used.
Your code also didn't apply rotation to the ornamentation. You need
something like this:
draw ((bbox lab) smoothed 4) rotatedaround (pos,rotation);
Note that this applies the rotation around the point position, so
alignment and rotation at the same time is weird. This is the same with
regular labels though - Therion bug that Bruce is fond of :) - so at
least this is consistent with Therion itself.
Your code hardcoded rotation to a very specific 0.001 degrees, which
was
weird. I assume you had intended to use 0 or a variable (my code uses
the rotation parameter of the point symbol).
interim bboxmargin:=6.5bp; % padding border->text
Just checking, since I don't know the "interim" keyword very well ...
Doesn't it need to be inside a "begingroup/endgroup" pair, in order to
know when to stop applying the "interim" value to the internal
bboxmargin variable?
As far as I can tell, you are modifying the global value of it, so all
subsequent uses of that internal variable will end up with your
padding.
At least until the next "endgroup" happens somewhere above your code
in
the stack.
This was correct. You needed to use begingroup+endgroup or use a vardef
instead of a def (with vardef, it automatically applies a
begingroup+endgroup). Therion's Metapost uses both of these approaches
to avoid the problem.
___
Therion mailing list
Therion@speleo.sk
https://mailman.speleo.sk/listinfo/therion
___
Therion mailing list
Therion@speleo.sk
https://mailman.speleo.sk/listinfo/therion