Debian Codegraph @

texmf-dist/metapost/metauml/metauml_note.mp

raw
1 % Copyright 2005 2015 Ovidiu Gheorghies
2 % Licensed under the Apache License, Version 2.0.
3
4 if known _metauml_note_mp:
5 expandafter endinput
6 fi;
7 _metauml_note_mp:=1;
8
9 % def metauml_note_debug text txt=log txt enddef;
10 def metauml_note_debug text txt= enddef;
11
12 % Sadly, this copy of the macro is needed to prevent multiple file loads being shown by MetaPost.
13 % The guard values (such as _metauml_mp) do ensure that the file isn't loaded multiple times,
14 % but this macro makes sure that MetaPost won't try to load the file and display a message for that.
15 def inputonce text libraryFile=
16 if not known scantokens ("_" & str libraryFile & "_mp"):
17 %includeonce% show "Loading " & str libraryFile;
18 scantokens ("input " & str libraryFile);
19 else:
20 %includeonce% show str libraryFile & " already loaded.";
21 fi;
22 enddef;
23
24 inputonce metauml_defaults;
25 inputonce util_log;
26
27 inputonce util_object;
28 inputonce util_picture_stack;
29 inputonce util_shade;
30 inputonce util_margins;
31
32 vardef NoteInfo@#=
33 attributes(@#);
34 var(color) foreColor, borderColor;
35 var(numeric) horizontalFolding, verticalFolding;
36
37 FontInfo.@#iFont(metauml_defaultFont, defaultscale);
38 @#iFont.ignoreNegativeBase := 1;
39
40 PictureInfo.@#iText (2, 2, 2, 2)(@#iFont);
41 PictureStackInfo.@#iStack (0, 0, 0, 0)(9)(@#iText);
42
43 @#iStack.iPict.ignoreNegativeBase := 1;
44
45 ShadeInfo.@#iShade;
46 Margins.@#(2,2,2,2);
47
48 @#foreColor := .9white;
49 @#borderColor := black;
50 @#horizontalFolding := 10;
51 @#verticalFolding := 10;
52 enddef;
53
54 vardef NoteInfoCopy@#(text src)=
55 attributes(@#);
56 var(color) foreColor, borderColor;
57
58 log "NoteInfoCopy: Copying usecase info";
59
60 PictureStackInfoCopy.@#iStack (src.iStack);
61 MarginsCopy.@#(src);
62 ShadeInfoCopy.@#iShade(src.iShade);
63
64 @#foreColor := src.foreColor;
65 @#borderColor := src.borderColor;
66 @#horizontalFolding := src.horizontalFolding;
67 @#verticalFolding := src.verticalFolding;
68 enddef;
69
70 NoteInfo.iNote;
71
72 vardef Note@#(text contents)=
73 ENote.@#(iNote)(contents);
74 enddef;
75
76 vardef ENote@#(text _info)(text contents)=
77 ObjectEquations(@#);
78 @#className := "Note";
79
80 NoteInfoCopy.@#info(_info);
81
82 %% The following code cannot work when pictures are given in the contents argument, such as in:
83 %% ENote.myNote(iNote)("This is a formula", TEX("$a=b$"));
84 %%
85 %numeric @#nLines; @#nLines := 0;
86 %string @#lines[];
87 %for l=contents:
88 % @#lines[@#nLines] := l;
89 % @#nLines := @#nLines + 1;
90 %endfor;
91 %
92 %EPictureStack.@#stack(@#info.iStack)(scantokens listArray(@#lines)(@#nLines))("vleftbase");
93
94 EPictureStack.@#stack(@#info.iStack)(contents)("vleftbase");
95 enddef;
96
97 vardef Note_layout@#=
98 if @#laidout = 1:
99 log "Note " & (str @#) & " has already been layed out";
100 else:
101 @#laidout := 1;
102 log "Note layout: " & (str @#);
103
104 PictureStack_layout.@#stack;
105
106 @#width = @#stack.width + @#info.left + @#info.right + @#info.horizontalFolding;
107 @#height = @#stack.height + @#info.top + @#info.bottom;
108
109 @#top = @#stack.top + @#info.top;
110 @#left = @#stack.left - @#info.left;
111 fi;
112 enddef;
113
114 vardef Note_draw@#=
115 Note_layout@#;
116 objectEnsurePositioning.@#;
117
118 attributes(@#);
119 var(path) border, corner;
120
121 @#border := @#nw -- (@#ne - (@#info.horizontalFolding, 0)) --
122 (@#ne - (0, @#info.verticalFolding) ) -- @#se -- @#sw -- cycle;
123
124 @#corner := (@#ne - (@#info.horizontalFolding, 0)) --
125 (@#ne - (@#info.horizontalFolding, @#info.verticalFolding)) --
126 (@#ne - (0, @#info.verticalFolding));
127
128 drawObjectShade(@#);
129
130 fill Note_border.@# withcolor @#info.foreColor;
131 draw Note_border.@# withcolor @#info.borderColor;
132
133 draw @#corner withcolor @#info.borderColor;
134 drawObject(@#stack);
135 enddef;
136
137 vardef Note_border@#=
138 @#border
139 enddef;
140