// Get Tex path
path[] p=texpath(lv_label);
filldraw(p,red,green);
// bounding box of label
draw(min(p)--(min(p).x,max(p).y)--max(p)--(max(p).x,min(p).y)--cycle);
// draw the label
label(lv_label);
The label as drawn by label is different in size as that drawn using the texpath.
The Tex path boundingbox is correct, but I don't understand why the labels differ.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi gummybears,
I don't have the solution for you, but I did notice that the "import labelpath;" command is not needed in the example. Also, removing the "size(1cm,1cm);" command causes the two labels to be the same size. Maybe that will help you figure out the root cause?
Good luck!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
As you understand, since the label is transformed in a path
the final size of the labelpath depends on the whole picture and is
adapted. On the other side, a standard label has the right size
(in 12pt by default) whatever the size of the picture is (and if no transformation is made on the label).
Yes it is related to deferred drawing (which I do not understand also).
Depending on your goal it is possible to have a label with the right
size + zero margin bounding box by using a frame. A frame is in postscript coordinates. For example
importfontsize;size(5cm,5cm);// use Helvetica, but not neededpenfontpen=Helvetica()+fontsize(40);Labellv_label;pairlv_pos;lv_pos=(2,1);lv_label=Label("Happy New Year",lv_pos,Align,fontpen);// Get Tex pathpath[]p=texpath(lv_label);framef;filldraw(f,p,red,green);draw(f,box(f,defaultpen+3bp));add(f);
Perhaps I do not answer exactly to your question.
O.G.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Happy New Year too, and to everyone on this list, well any list.
Thanks for your detailed answer.
My goal is just to get the bounding box of the label (irrespective of
its font size, with zero margin, in user coordinates) and use the information to do some extra drawing. I will investigate both examples to see where I need to change my code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am not sure that it is possible to compute the exact bounding box
of the label in the user coordinate, since a new draw command can change
all. However you can study deeply the deferred drawing and flowchart.asy
and any drawing is possible around a label, between two labels.
For example
importfontsize;size(15cm,15cm);// use Helvetica, but not neededpenfontpen=Helvetica()+fontsize(40);Labellv_label;pairlv_pos;lv_pos=(2,1);lv_label=Label("Happy New Year",lv_pos,Align,fontpen);// Get Tex pathpath[]p=texpath(lv_label);framef1;filldraw(f1,p,red,green);draw(f1,box(f1,defaultpen+3bp));add(f1,(0,1));framef2;filldraw(f2,p,red,green);draw(f2,box(f2,defaultpen+3bp));add(f2,(1,2));add(newvoid(picturepic,transformt){paira=t*(0,1)+size(f1)-5bp*dir((1,1));pairb=t*(1,2);paths=a{-2,0}..b{1,0};draw(pic,s,red+4bp);});
Another solution is to work with 1bp unitsize.
Last edit: Olivier Guibé 2015-01-08
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What I try to do is to get the exact bounding box of
a label with no margins.
This is what I tested
import labelpath;
size(1cm,1cm);
// use Helvetica, but not needed
pen fontpen = Helvetica();
Label lv_label;
pair lv_pos;
lv_pos = (2,1);
lv_label = Label("text",pos,Align,fontpen);
// Get Tex path
path[] p=texpath(lv_label);
filldraw(p,red,green);
// bounding box of label
draw(min(p)--(min(p).x,max(p).y)--max(p)--(max(p).x,min(p).y)--cycle);
// draw the label
label(lv_label);
The label as drawn by label is different in size as that drawn using the texpath.
The Tex path boundingbox is correct, but I don't understand why the labels differ.
Hi gummybears,
I don't have the solution for you, but I did notice that the "import labelpath;" command is not needed in the example. Also, removing the "size(1cm,1cm);" command causes the two labels to be the same size. Maybe that will help you figure out the root cause?
Good luck!
Hi James,
I now understand the problem, it has to do with deferred drawing, which I don't understand (yet).
Thanks James for helping.
Last edit: gummybears 2015-01-05
Hello
As you understand, since the label is transformed in a path
the final size of the labelpath depends on the whole picture and is
adapted. On the other side, a standard label has the right size
(in 12pt by default) whatever the size of the picture is (and if no transformation is made on the label).
Yes it is related to deferred drawing (which I do not understand also).
Depending on your goal it is possible to have a label with the right
size + zero margin bounding box by using a frame. A frame is in postscript coordinates. For example
Perhaps I do not answer exactly to your question.
O.G.
Hi Olivier
Happy New Year too, and to everyone on this list, well any list.
Thanks for your detailed answer.
My goal is just to get the bounding box of the label (irrespective of
its font size, with zero margin, in user coordinates) and use the information to do some extra drawing. I will investigate both examples to see where I need to change my code.
Hi
I am not sure that it is possible to compute the exact bounding box
of the label in the user coordinate, since a new draw command can change
all. However you can study deeply the deferred drawing and flowchart.asy
and any drawing is possible around a label, between two labels.
For example
Another solution is to work with 1bp unitsize.
Last edit: Olivier Guibé 2015-01-08