summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/metauml/util_picture.mp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/metapost/metauml/util_picture.mp')
-rw-r--r--Master/texmf-dist/metapost/metauml/util_picture.mp95
1 files changed, 81 insertions, 14 deletions
diff --git a/Master/texmf-dist/metapost/metauml/util_picture.mp b/Master/texmf-dist/metapost/metauml/util_picture.mp
index fc9133392d9..b148f04857e 100644
--- a/Master/texmf-dist/metapost/metauml/util_picture.mp
+++ b/Master/texmf-dist/metapost/metauml/util_picture.mp
@@ -20,9 +20,21 @@ if known _util_picture_mp:
fi;
_util_picture_mp:=1;
-input util_log;
+% Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost.
+% The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times,
+% but this macro makes sure that MetaPost won't try to load the file and display a message for that.
+def inputonce text libraryFile=
+ if not known scantokens ("_" & str libraryFile & "_mp"):
+ %includeonce% show "Loading " & str libraryFile;
+ scantokens ("input " & str libraryFile);
+ else:
+ %includeonce% show str libraryFile & " already loaded.";
+ fi;
+enddef;
+
+inputonce util_log;
+inputonce util_margins;
-input util_margins;
if not known _n_cur_:input boxes;fi;
vardef FontInfo@#(expr tname, tscale)=
@@ -65,13 +77,38 @@ vardef PictureInfo@#(expr pleft, pright, ptop, pbottom)(text pfont)=
var(color) borderColor;
var(numeric) boxed;
+ %% Used to set the base of a text to the natural base of the letters.
+ %% If set to '1', 'y' and 'a' will have the same base line, the tail
+ %% of 'y' being rendered below that line
+ %%
var(numeric) ignoreNegativeBase;
+ %% If these attributes are set to -1, the height and width of the
+ %% Picture object is deduced from the dimensions of the contained
+ %% object (picture or text). If one of these parameters is set to
+ %% a positive value, then the given value is used, regardless of the
+ %% size of the contents.
+ %%
+ var(numeric) fixedWidth, fixedHeight;
+
+ %% Controls how the contents of the picture is to be alligned relatively
+ %% to the picture margins. Can be one of "left", "centered", defaults to
+ %% "left". The "centered" setting is useful for Picture-s whose fixedWidth
+ %% is set to a given value.
+ %%
+ var(string) halign, valign;
+
@#boxed := 0;
@#borderColor := blue;
@#ignoreNegativeBase := 0;
+ @#fixedWidth := -1;
+ @#fixedHeight := -1;
+
+ @#halign := "left";
+ @#valign := "bottom";
+
Margins.@#(pleft, pright, ptop, pbottom);
FontInfoCopy.@#iFont(pfont);
@@ -83,6 +120,12 @@ vardef PictureInfoCopy@#(text src)=
@#boxed := src.boxed;
@#borderColor := src.borderColor;
@#ignoreNegativeBase := src.ignoreNegativeBase;
+
+ @#fixedWidth := src.fixedWidth;
+ @#fixedHeight := src.fixedHeight;
+
+ @#halign := src.halign;
+ @#valign := src.valign;
enddef;
vardef PictureInfo_toString@#=
@@ -139,7 +182,9 @@ enddef;
%% Lays out the Picture.
%%
vardef Picture_layout@# =
- if @#layedout = 0:
+ if @#layedout = 1:
+ log "Picture " & str @# & " already layed out.";
+ else:
log "Laying out " & (str @#);
@#layedout := 1;
@@ -148,28 +193,50 @@ vardef Picture_layout@# =
log "Content is known to be a picture";
@#pict = @#contentAsPicture;
elseif known @#contentAsString:
- log "Content is known to be a string";
- log @#contentAsString;
+ log "Content is known to be a string: " & @#contentAsString;
@#pict = @#contentAsString infont @#info.iFont.name scaled @#info.iFont.scale;
else:
log "Show unknown parameter type in picture layout";
- 2 = 3;
+ 2 = 3; % force an error
fi;
@#negativeBase = ypart llcorner @#pict;
- @#width = pictWidth(@#pict) + @#info.left + @#info.right;
-
if @#info.ignoreNegativeBase = 0:
- @#height = pictHeight(@#pict) + @#info.top + @#info.bottom;
- @#contentShift = @#sw + (@#info.left, @#info.bottom - @#negativeBase) ;
+ negativeBaseAdjustement__ := 0;
+ else:
+ negativeBaseAdjustement__ := @#negativeBase;
+ fi;
+
+ if @#info.fixedWidth = -1:
+ @#width = pictWidth(@#pict) + @#info.left + @#info.right;
else:
- @#height = pictHeight(@#pict) + @#info.top + @#info.bottom + @#negativeBase;
- @#contentShift = @#sw + (@#info.left, @#info.bottom);
+ @#width = @#info.fixedWidth;
fi;
- else:
- log "Picture " & str @# & " already layed out.";
+ if @#info.fixedHeight = -1:
+ @#height = pictHeight(@#pict) + @#info.top + @#info.bottom + negativeBaseAdjustement__;
+ else:
+ @#height = @#info.fixedHeight;
+ fi;
+
+ if @#info.halign = "left":
+ xdelta__ := @#info.left;
+ elseif @#info.halign = "center":
+ xdelta__ := (@#width-pictWidth(@#pict))/2;
+ else:
+ 2 = 3; % throw exception illegal value for @#info.hallign
+ fi;
+
+ if @#info.valign = "bottom":
+ ydelta__ := @#info.bottom - @#negativeBase + negativeBaseAdjustement__;
+ elseif @#info.valign = "center":
+ ydelta__ := (@#height-pictHeight(@#pict))/2 - @#negativeBase + negativeBaseAdjustement__;
+ else:
+ 2 = 3; % throw exception illegal value for @#info.vallign
+ fi;
+
+ @#contentShift = @#sw + (xdelta__, ydelta__);
fi;
enddef;