Quiq/LaTeX/Figure.pm

filter: Statementstmt 39.7% 27 / 68 Branchbran 7.1% 3 / 42 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 31.5% 40 / 127 CC 24 SCAR 58.2
CC
24
Cov
27%
latex
422.2
BEGIN
1.0
BEGIN
1.0
CRAP 338.0
« Quiq/Axis/Numeric.pm ↑ Summary Quiq/Html/Listing.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::LaTeX::Figure - Erzeuge LaTeX Figure
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Hash>
12  
13 =head1 SYNOPSIS
14  
15 Der Code
16  
17 use Quiq::LaTeX::Figure;
18 use Quiq::LaTeX::Code;
19
20 my $doc = Quiq::LaTeX::Figure->new(
21 FIXME
22 );
23
24 my $l = Quiq::LaTeX::Code->new;
25 my $code = $tab->latex($l);
26  
27 produziert
28  
29 FIXME
30  
31 =cut
32  
33 # -----------------------------------------------------------------------------
34  
35 package Quiq::LaTeX::Figure;
36 1 ▶use base qw/Quiq::Hash/;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 1 our $VERSION = '1.240';
43  
44 1 ▶use Quiq::Reference;
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 # -----------------------------------------------------------------------------
47  
48 =head1 METHODS
49  
50 =head2 Konstruktor
51  
52 =head3 new() - Instantiiere LaTeX Figure-Objekt
53  
54 =head4 Synopsis
55  
56 $doc = $class->new(@keyVal);
57  
58 =head4 Arguments
59  
60 =over 4
61  
62 =item align => 'left' | 'center' (Default: 'center')
63  
64 Ausrichtung der Abbildung auf der Seite. Nur der erste Buchstabe
65 des Werts wird interpretiert.
66  
67 =item border => $bool (Default: 0)
68  
69 Zeichne einen Rahmen um die Abbildung.
70  
71 =item padding => $length (Default: '0pt')
72  
73 Zeichne den Rahmen (Attribut C<border>) mit dem angegebenen
74 Abstand um die Abbildung.
75  
76 =item caption => $text
77  
78 Beschriftung der Abbldung. Diese erscheint unter der Abbildung.
79  
80 =item file => $path
81  
82 Pfad der Bilddatei.
83  
84 =item height => $height
85  
86 Höhe in Pixel (ohne Angabe einer Einheit), auf die das Bild
87 skaliert wird. Der Wert wird für LaTeX in pt umgerechnet (1px =
88 0.75pt).
89  
90 =item indent => $length
91  
92 Länge, mit der die Abbildung vom linken Rand eingerückt wird,
93 wenn sie links (Attribut C<align>) gesetzt wird.
94  
95 =item inline => $bool (Default: 0)
96  
97 Anstelle von Code für eine alleinstehende Abbildung wird Code
98 für eine Inline-Grafik erzeugt.
99  
100 =item label => $str
101  
102 Anker der Abbildung.
103  
104 =item options => $str | \@arr
105  
106 Optionen, die an das Makro C<\includegraphics> übergeben werden.
107  
108 =item position => 'H','h','t','b','p' (Default: 'H')
109  
110 Positioniergspräferenz für das Gleitobjekt. Details siehe
111 LaTeX-Package C<float>, das geladen werden muss.
112  
113 =item postVSpace => $length
114  
115 Vertikaler Leerraum, der nach der Abbildung hinzugefügt (positiver
116 Wert) oder abgezogen (negativer Wert) wird.
117  
118 =item link => $latex,
119  
120 Versieh das Bild mit einem Verweis. Übergeben wird der fertige
121 LaTeX-Code für den Verweis auf das interne bzw. externe Ziel. Der
122 Code muss %s an der Stelle enthalten, wo die Methode den Code für
123 das Bild eingesetzen soll.
124  
125 =item scale => $factor
126  
127 Skalierungsfaktor. Der Skalierungsfaktor hat Priorität gegenüber
128 der Angabe von C<width> und C<height>.
129  
130 =item url => $url
131  
132 Versieh das Bild mit einem Verweis auf eine externe Ressource.
133 Ist auch Attribut C<ref> gesetzt, hat dieses Priorität.
134  
135 =item width => $width
136  
137 Breite in Pixel (ohne Angabe einer Einheit), auf die das Bild
138 skaliert wird. Der Wert wird für LaTeX in pt umgerechnet (1px =
139 0.75pt).
140  
141 =back
142  
143 =head4 Returns
144  
145 Figure-Objekt
146  
147 =head4 Description
148  
149 Instantiiere ein LaTeX Figure-Objekt und liefere eine Referenz auf
150 dieses Objekt zurück.
151  
152 =cut
153  
154 # -----------------------------------------------------------------------------
155  
156 1 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
157 1 my $class = shift;
158 # @_: @keyval
159  
160 1 my $self = $class->SUPER::new(
161 align => undef,
162 border => 0,
163 caption => undef,
164 file => undef,
165 height => undef,
166 indent => undef,
167 inline => 0,
168 label => undef,
169 link => undef,
170 options => undef, # $str | \@opt
171 padding => '0pt',
172 position => 'H',
173 postVSpace => undef,
174 scale => undef,
175 width => undef,
176 );
177 1 $self->set(@_);
178  
179 1 return $self;
180 }
181  
182 # -----------------------------------------------------------------------------
183  
184 =head2 Objektmethoden
185  
186 =head3 latex() - Generiere LaTeX-Code
187  
188 =head4 Synopsis
189  
190 $code = $fig->latex($l);
191 $code = $class->latex($l,@keyVal);
192  
193 =head4 Description
194  
195 Generiere den LaTeX-Code des Objekts und liefere diesen
196 zurück. Als Klassenmethode gerufen, wird das Objekt intern erzeugt
197 und mit den Attributen @keyVal instantiiert.
198  
199 =cut
200  
201 # -----------------------------------------------------------------------------
202  
203 1 ▶sub latex {
Subroutine latex: called CC=24 SCAR=60.5
Pod documented
204 1 my $this = shift;
205 1 my $l = shift;
206  
207 1 ▶ my $self = ref $this? $this: $this->new(@_);
Branch: 1 branch
BranchTrueFalseTotal
ref $this ? : 1 0 1
208  
209 1 my ($align,$border,$caption,$file,$height,$indent,$inline,$label,$link,
210 $options,$padding,$position,$postVSpace,$scale,$width) =
211 $self->get(qw/align border caption file height indent inline label
212 link options padding position postVSpace scale width/);
213  
214 1 ▶ $align //= $inline? '': 'center';
Branch: 1 branch
BranchTrueFalseTotal
$inline ? : 0 1 1
Condition50%1/2
$align //= $inline ? "" : "center"
l!l
01
MC/DC0%0/1
$align //= $inline ? "" : "center"
$align
Truth table50%1/2
A
A= $align
Aresult
11
00
215  
216 1 ▶ if (!$file) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($file) 1 0 1
217 1 return '';
218 }
219  
220 0 my @opt;
221 0 ▶ if ($scale) {
Branch: 1 branch
BranchTrueFalseTotal
if ($scale) { } 0 0 0
222 # $scale hat Priorität gegenüber width und height
223 0 push @opt,"scale=$scale";
224 }
225 else {
226 0 ▶ if ($width) {
Branch: 1 branch
BranchTrueFalseTotal
if ($width) 0 0 0
227 0 push @opt,"width=$width";
228 }
229 0 ▶ if ($height) {
Branch: 1 branch
BranchTrueFalseTotal
if ($height) 0 0 0
230 0 push @opt,"height=$height";
231 }
232 }
233 0 ▶ if (defined $options) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options) 0 0 0
234 0 ▶ if (Quiq::Reference->isArrayRef($options)) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Quiq::Reference'->isArrayRef($options)) { } 0 0 0
235 0 @opt = @$options;
236 }
237 else {
238 0 @opt = split /,/,$options;
239 }
240 }
241  
242 0 my $code;
243 0 ▶ if ($inline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline) 0 0 0
244 0 $code .= $l->ci('\protect');
245 }
246 0 $code .= $l->macro('\includegraphics',
247 -o => \@opt,
248 -p => $file,
249 -nl => 0,
250 );
251 0 ▶ if ($border) {
Branch: 1 branch
BranchTrueFalseTotal
if ($border) 0 0 0
252 0 $code = $l->ci('{\fboxsep%s\fbox{%s}}',$padding,$code);
253 }
254 0 ▶ if ($link) {
Branch: 1 branch
BranchTrueFalseTotal
if ($link) 0 0 0
255 # $link muss %s enthalten
256 0 $code = sprintf $link,$code;
257 }
258 0 ▶ if ($indent && $align ne 'center') {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent and $align ne "center") 0 0 0
Condition0%0/3
$indent and $align ne "center"
!ll&&!rl&&r
000
MC/DC0%0/2
$indent and $align ne "center"
$indent $align ne "center"
Truth table0%0/3
A and B
A= $indentB= $align ne "center"
ABresult
0X0
100
111
259 0 $code = $l->ci('\hspace*{%s}',$indent).$code;
260 }
261  
262 # Abbildung inline
263  
264 0 ▶ if ($inline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inline) 0 0 0
265 0 return "{$code}";
266 }
267  
268 # Alleinstehende Abbildung
269  
270 0 ▶ if (!$inline) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inline) 0 0 0
271 0 ▶ if ($align eq 'center') {
Branch: 1 branch
BranchTrueFalseTotal
if ($align eq "center") 0 0 0
272 0 $code = $l->c('\centering').$code;
273 }
274 }
275  
276 0 ▶ if ($caption) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caption) 0 0 0
277 0 my @opt;
278 0 ▶ if ($align ne 'center') {
Branch: 1 branch
BranchTrueFalseTotal
if ($align ne "center") 0 0 0
279 0 push @opt,'singlelinecheck=off';
280 0 ▶ if ($indent) {
Branch: 1 branch
BranchTrueFalseTotal
if ($indent) 0 0 0
281 0 push @opt,"margin=$indent";
282 }
283 }
284 0 ▶ if (@opt) {
Branch: 1 branch
BranchTrueFalseTotal
if (@opt) 0 0 0
285 0 $code .= $l->c('\captionsetup{%s}',\@opt);
286 }
287 0 $code .= $l->c('\caption{%s}',$caption);
288 }
289 0 ▶ if ($label) {
Branch: 1 branch
BranchTrueFalseTotal
if ($label) 0 0 0
290 0 $code .= $l->c('\label{%s}',$label);
291 }
292  
293 0 $code = $l->env('figure',$code,
294 -o => $position,
295 );
296  
297 0 ▶ if (my $postVSpace = $self->postVSpace) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $postVSpace = $self->postVSpace) 0 0 0
298 0 $code .= $l->c('\vspace{%s}','--',$postVSpace);
299 }
300
301 0 return $code;
302 }
303  
304 # -----------------------------------------------------------------------------
305  
306 =head1 VERSION
307  
308 1.240
309  
310 =head1 AUTHOR
311  
312 Frank Seitz, L<http://fseitz.de/>
313  
314 =head1 COPYRIGHT
315  
316 Copyright (C) 2026 Frank Seitz
317  
318 =head1 LICENSE
319  
320 This code is free software; you can redistribute it and/or modify
321 it under the same terms as Perl itself.
322  
323 =cut
324  
325 # -----------------------------------------------------------------------------
326  
327 1 1;
328  
329 # eof
« Quiq/Axis/Numeric.pm ↑ Summary Quiq/Html/Listing.pm »