lib/LaTeXML/Common/Font.pm

filter: Statementstmt 16.8% 79 / 468 Branchbran 0.0% 0 / 318 Conditioncond 0.0% 0 / 266 MC/DCmcdc 0.0% 0 / 148 Subroutinesub 23.8% 15 / 63 Podpod 8.5% 4 / 47 totaltotal 7.4% 98 / 1310 CC 259 SCAR 65.1
CC
259
Cov
8%
computeBoxesSize
2342.0
merge
1332.0
specialize
930.0
CRAP 671.8
« lib/LaTeXML/Util/Pack.pm ↑ Summary lib/LaTeXML/Post/MakeBibliography.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Font | #
3 # | Representaion of Fonts | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Common::Font;
13 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LaTeXML::Core::Token;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use LaTeXML::Common::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use LaTeXML::Common::Number;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use LaTeXML::Common::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use LaTeXML::Common::Font::Metric;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 ▶use LaTeXML::Common::Font::StandardMetrics;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 5 ▶use LaTeXML::Common::Color;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 5 ▶use List::Util qw(min max sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 5 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 # Note that this has evolved way beynond just "font",
28 # but covers text properties (or even display properties) in general
29 # including basic font information, color & background color
30 # as well as encoding and language information.
31  
32 5 DebuggableFeature('size-detailed', "Show sizing of boxes in detail");
33 # NOTE: This is now in Common that it may evolve to be useful in Post processing...
34  
35 5 my $DEFFAMILY = 'serif'; # [CONSTANT]
36 5 my $DEFSERIES = 'medium'; # [CONSTANT]
37 5 my $DEFSHAPE = 'upright'; # [CONSTANT]
38 5 my $DEFCOLOR = Black; # [CONSTANT]
39 5 my $DEFBACKGROUND = undef; # [CONSTANT] no color; transparent
40 5 my $DEFOPACITY = '1'; # [CONSTANT]
41 5 my $DEFENCODING = 'OT1'; # [CONSTANT]
42 5 my $DEFLANGUAGE = undef;
43  
44 0 ▶sub DEFSIZE { return $STATE->lookupValue('NOMINAL_FONT_SIZE') || 10; }
Subroutine DEFSIZE: not called CC=2 SCAR=17.9
Pod undocumented
Condition0%0/2
$LaTeXML::Common::Font::STATE->lookupValue('NOMINAL_FONT_SIZE') || 10
l!l
00
MC/DC0%0/1
$LaTeXML::Common::Font::STATE->lookupValue('NOMINAL_FONT_SIZE') || 10
$LaTeXML::Common::Font::STATE->lookupValue('NOMINAL_FONT_SIZE')
Truth table0%0/2
A
A= $LaTeXML::Common::Font::STATE->lookupValue('NOMINAL_FONT_SIZE')
Aresult
11
00
45  
46 5 my $FLAG_FORCE_FAMILY = 0x1;
47 5 my $FLAG_FORCE_SERIES = 0x2;
48 5 my $FLAG_FORCE_SHAPE = 0x4;
49 5 my $FLAG_EMPH = 0x10;
50  
51 #======================================================================
52 # Mappings from various forms of names or component names in TeX
53 # Given a font, we'd like to map it to the "logical" names derived from LaTeX,
54 # (w/ loss of fine grained control).
55 # I'd like to use Karl Berry's font naming scheme
56 # (See http://www.tug.org/fontname/html/)
57 # but it seems to be a one-way mapping, and moreover, doesn't even fit CM fonts!
58 # We'll assume a sloppier version:
59 # family + series + variant + size
60 # NOTE: This probably doesn't really belong in here...
61  
62 5 my %font_family = (
63 cmr => { family => 'serif' }, cmss => { family => 'sansserif' },
64 cmtt => { family => 'typewriter' }, cmvtt => { family => 'typewriter' },
65 cmti => { family => 'typewriter', shape => 'italic' },
66 cmfib => { family => 'serif' }, cmfr => { family => 'serif' },
67 cmdh => { family => 'serif' }, cm => { family => 'serif' },
68 ptm => { family => 'serif' }, ppl => { family => 'serif' },
69 pnc => { family => 'serif' }, pbk => { family => 'serif' },
70 phv => { family => 'sansserif' }, pag => { family => 'serif' },
71 pcr => { family => 'typewriter' }, pzc => { family => 'script' },
72 put => { family => 'serif' }, bch => { family => 'serif' },
73 psy => { family => 'symbol' }, pzd => { family => 'dingbats' },
74 ccr => { family => 'serif' }, ccy => { family => 'symbol' },
75 cmbr => { family => 'sansserif' }, cmtl => { family => 'typewriter' },
76 cmbrs => { family => 'symbol' }, ul9 => { family => 'typewriter' },
77 txr => { family => 'serif' }, txss => { family => 'sansserif' },
78 txtt => { family => 'typewriter' }, txms => { family => 'symbol' },
79 txsya => { family => 'symbol' }, txsyb => { family => 'symbol' },
80 pxr => { family => 'serif' }, pxms => { family => 'symbol' },
81 pxsya => { family => 'symbol' }, pxsyb => { family => 'symbol' },
82 futs => { family => 'serif' },
83 uaq => { family => 'serif' }, ugq => { family => 'sansserif' },
84 eur => { family => 'serif' }, eus => { family => 'script' },
85 euf => { family => 'fraktur' }, euex => { family => 'symbol' },
86 # The following are actually math fonts.
87 ms => { family => 'symbol' },
88 ccm => { family => 'serif', shape => 'italic' },
89 cmm => { family => 'italic', encoding => 'OML' },
90 cmex => { family => 'symbol', encoding => 'OMX' }, # Not really symbol, but...
91 cmsy => { family => 'symbol', encoding => 'OMS' },
92 ccitt => { family => 'typewriter', shape => 'italic' },
93 cmbrm => { family => 'sansserif', shape => 'italic' },
94 futm => { family => 'serif', shape => 'italic' },
95 futmi => { family => 'serif', shape => 'italic' },
96 txmi => { family => 'serif', shape => 'italic' },
97 pxmi => { family => 'serif', shape => 'italic' },
98 bbm => { family => 'blackboard' },
99 bbold => { family => 'blackboard' },
100 bbmss => { family => 'blackboard' },
101 # some ams fonts
102 cmmib => { family => 'italic', series => 'bold' },
103 cmbsy => { family => 'symbol', series => 'bold' },
104 msa => { family => 'symbol', encoding => 'AMSa' },
105 msb => { family => 'symbol', encoding => 'AMSb' },
106 # Are these really the same?
107 msx => { family => 'symbol', encoding => 'AMSa' },
108 msy => { family => 'symbol', encoding => 'AMSb' },
109 # Pretend to recognize xy's fonts
110 xydash => { family => 'graphic' },
111 xyatip => { family => 'graphic' },
112 xybtip => { family => 'graphic' },
113 xybsql => { family => 'graphic' },
114 xycirc => { family => 'graphic' },
115 xycmat => { family => 'graphic' },
116 xycmbt => { family => 'graphic' },
117 xyluat => { family => 'graphic' },
118 xylubt => { family => 'graphic' },
119 );
120  
121 # Maps the "series code" to an abstract font series name
122 5 my %font_series = (
123 '' => { series => 'medium' }, m => { series => 'medium' }, mc => { series => 'medium' },
124 b => { series => 'bold' }, bc => { series => 'bold' }, bx => { series => 'bold' },
125 sb => { series => 'bold' }, sbc => { series => 'bold' }, bm => { series => 'bold' });
126  
127 # Maps the "shape code" to an abstract font shape name.
128 5 my %font_shape = ('' => { shape => 'upright' }, n => { shape => 'upright' }, i => { shape => 'italic' }, it => { shape => 'italic' },
129 sl => { shape => 'slanted' }, sc => { shape => 'smallcaps' }, csc => { shape => 'smallcaps' });
130  
131 # These could be exported...
132 0 ▶sub lookupFontFamily {
Subroutine lookupFontFamily: not called CC=1 SCAR=6.9
Pod undocumented
133 0 my ($familycode) = @_;
134 0 return $font_family{ ToString($familycode) }; }
135  
136 0 ▶sub lookupFontSeries {
Subroutine lookupFontSeries: not called CC=1 SCAR=6.9
Pod undocumented
137 0 my ($seriescode) = @_;
138 0 return $font_series{ ToString($seriescode) }; }
139  
140 0 ▶sub lookupFontShape {
Subroutine lookupFontShape: not called CC=1 SCAR=6.9
Pod undocumented
141 0 my ($shapecode) = @_;
142 0 return $font_shape{ ToString($shapecode) }; }
143  
144 # Symbolic font sizes, relative to the NOMINAL_FONT_SIZE (often 10)
145 # extended logical font sizes, based on nominal document size of 10pts
146 # Possibly should simply use absolute font point sizes, as declared in class...
147 5 my %font_size = (
148 tiny => 0.5, SMALL => 0.7, Small => 0.8, small => 0.9,
149 normal => 1.0, large => 1.2, Large => 1.44, LARGE => 1.728,
150 huge => 2.074, Huge => 2.488,
151 big => 1.2, Big => 1.6, bigg => 2.1, Bigg => 2.6,
152 );
153  
154 0 ▶sub rationalizeFontSize {
Subroutine rationalizeFontSize: not called CC=3 SCAR=24.8
Pod undocumented
155 0 my ($size) = @_;
156 0 ▶ return unless defined $size;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
157 0 ▶ if (my $symbolic = $font_size{$size}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $symbolic = $font_size{$size}) 0 0 0
158 0 return $symbolic * DEFSIZE(); }
159 0 return $size; }
160  
161 # convert to percent
162 0 ▶sub relativeFontSize {
Subroutine relativeFontSize: not called CC=1 SCAR=6.9
Pod undocumented
163 0 my ($newsize, $oldsize) = @_;
164 0 return int(0.5 + 100 * $newsize / $oldsize) . '%'; }
165  
166 my $FONTREGEXP
167 1821 = '(' . join('|', sort { -($a cmp $b) } keys %font_family) . ')'
168 99 . '(' . join('|', sort { -($a cmp $b) } keys %font_series) . ')'
169 5 . '(' . join('|', sort { -($a cmp $b) } keys %font_shape) . ')'
170 . '(\d*)';
171  
172 0 ▶sub decodeFontname {
Subroutine decodeFontname: not called CC=10 SCAR=47.0
Pod undocumented
173 0 my ($name, $at, $scaled) = @_;
174 0 ▶ if ($name =~ /^$FONTREGEXP$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^$FONTREGEXP$/o) { } 0 0 0
175 0 my %props;
176 0 my ($fam, $ser, $shp, $size) = ($1, $2, $3, $4);
177 0 ▶ if (my $ffam = lookupFontFamily($fam)) { map { $props{$_} = $$ffam{$_} } keys %$ffam; }
Branch: 1 branch
BranchTrueFalseTotal
if (my $ffam = lookupFontFamily($fam)) 0 0 0
178 0 ▶ if (my $fser = lookupFontSeries($ser)) { map { $props{$_} = $$fser{$_} } keys %$fser; }
Branch: 1 branch
BranchTrueFalseTotal
if (my $fser = lookupFontSeries($ser)) 0 0 0
179 0 ▶ if (my $fsh = lookupFontShape($shp)) { map { $props{$_} = $$fsh{$_} } keys %$fsh; }
Branch: 1 branch
BranchTrueFalseTotal
if (my $fsh = lookupFontShape($shp)) 0 0 0
180 0 ▶ $size = 1 unless $size; # Yes, also if 0, "" (from regexp)
Branch: 1 branch
BranchTrueFalseTotal
unless $size 0 0 0
181 0 ▶ $size = $at if defined $at;
Branch: 1 branch
BranchTrueFalseTotal
if defined $at 0 0 0
182 0 ▶ $size *= $scaled if defined $scaled;
Branch: 1 branch
BranchTrueFalseTotal
if defined $scaled 0 0 0
183 0 $props{size} = $size;
184 # Experimental Hack !?!?!?
185 0 ▶ $props{encoding} = 'OT1' unless defined $props{encoding};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $props{"encoding"} 0 0 0
186 0 ▶ $props{at} = $at . "pt" if defined $at;
Branch: 1 branch
BranchTrueFalseTotal
if defined $at 0 0 0
187 0 return %props; }
188 else {
189 0 return; } }
190  
191 0 ▶sub lookupTeXFont {
Subroutine lookupTeXFont: not called CC=4 SCAR=30.0
Pod undocumented
192 0 my ($fontname, $seriescode, $shapecode) = @_;
193 0 my %props;
194 0 ▶ if (my $ffam = lookupFontFamily($fontname)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ffam = lookupFontFamily($fontname)) 0 0 0
195 0 map { $props{$_} = $$ffam{$_} } keys %$ffam; }
196 0 ▶ if (my $fser = lookupFontSeries($seriescode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fser = lookupFontSeries($seriescode)) 0 0 0
197 0 map { $props{$_} = $$fser{$_} } keys %$fser; }
198 0 ▶ if (my $fsh = lookupFontShape($shapecode)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $fsh = lookupFontShape($shapecode)) 0 0 0
199 0 map { $props{$_} = $$fsh{$_} } keys %$fsh; }
200 0 return %props; }
201  
202 #======================================================================
203 # NOTE: Would it make sense to allow compnents to be `inherit' ??
204  
205 # Note: forcefamily, forceseries, forceshape (& forcebold for compatibility)
206 # are only useful for fonts in math; See the specialize method below.
207 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
208 0 my ($class, %options) = @_;
209 0 my $family = $options{family};
210 0 my $series = $options{series};
211 0 my $shape = $options{shape};
212 0 my $size = $options{size};
213 0 my $color = $options{color};
214 0 my $bg = $options{background};
215 0 my $opacity = $options{opacity};
216 0 my $encoding = $options{encoding};
217 0 my $language = $options{language};
218 0 my $mathstyle = $options{mathstyle};
219  
220 0 ▶ if ($options{forcebold}) { # for compatibility
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"forcebold"}) 0 0 0
221 0 $series = 'bold'; $options{forceseries} = 1; }
222 my $flags = 0
223 | ($options{forcefamily} ? $FLAG_FORCE_FAMILY : 0)
224 | ($options{forceseries} ? $FLAG_FORCE_SERIES : 0)
225 0 ▶ | ($options{forceshape} ? $FLAG_FORCE_SHAPE : 0);
Branch: 3 branches
BranchTrueFalseTotal
$options{'forcefamily'} ? : 0 0 0
$options{'forceseries'} ? : 0 0 0
$options{'forceshape'} ? : 0 0 0
226 0 return $class->new_internal(
227 $family, $series, $shape, rationalizeFontSize($size),
228 $color, $bg, $opacity,
229 $encoding, $language,
230 $mathstyle, $flags); }
231  
232 0 ▶sub new_internal {
Subroutine new_internal: not called CC=1 SCAR=6.9
Pod undocumented
233 0 my ($class, @components) = @_;
234 0 return bless [@components], $class; }
235  
236 0 ▶sub textDefault {
Subroutine textDefault: not called CC=1 SCAR=6.9
Pod undocumented
237 0 my ($self) = @_;
238 0 return $self->new_internal($DEFFAMILY, $DEFSERIES, $DEFSHAPE, DEFSIZE(),
239 $DEFCOLOR, $DEFBACKGROUND, $DEFOPACITY, $DEFENCODING, $DEFLANGUAGE, undef, 0); }
240  
241 0 ▶sub mathDefault {
Subroutine mathDefault: not called CC=1 SCAR=6.9
Pod undocumented
242 0 my ($self) = @_;
243 0 return $self->new_internal('math', $DEFSERIES, 'italic', DEFSIZE(),
244 $DEFCOLOR, $DEFBACKGROUND, $DEFOPACITY, undef, $DEFLANGUAGE, 'text', 0); }
245  
246 # Accessors
247 # Using an array here is getting ridiculous!
248 0 ▶sub getFamily { my ($self) = @_; return $$self[0]; }
Subroutine getFamily: not called CC=1 SCAR=6.9
Pod undocumented
249 0 ▶sub getSeries { my ($self) = @_; return $$self[1]; }
Subroutine getSeries: not called CC=1 SCAR=6.9
Pod undocumented
250 0 ▶sub getShape { my ($self) = @_; return $$self[2]; }
Subroutine getShape: not called CC=1 SCAR=6.9
Pod undocumented
251 0 ▶sub getSize { my ($self) = @_; return $$self[3]; }
Subroutine getSize: not called CC=1 SCAR=6.9
Pod undocumented
252 0 ▶sub getColor { my ($self) = @_; return $$self[4]; }
Subroutine getColor: not called CC=1 SCAR=6.9
Pod undocumented
253 0 ▶sub getBackground { my ($self) = @_; return $$self[5]; }
Subroutine getBackground: not called CC=1 SCAR=6.9
Pod undocumented
254 0 ▶sub getOpacity { my ($self) = @_; return $$self[6]; }
Subroutine getOpacity: not called CC=1 SCAR=6.9
Pod undocumented
255 0 ▶sub getEncoding { my ($self) = @_; return $$self[7]; }
Subroutine getEncoding: not called CC=1 SCAR=6.9
Pod undocumented
256 0 ▶sub getLanguage { my ($self) = @_; return $$self[8]; }
Subroutine getLanguage: not called CC=1 SCAR=6.9
Pod undocumented
257 0 ▶sub getMathstyle { my ($self) = @_; return $$self[9]; }
Subroutine getMathstyle: not called CC=1 SCAR=6.9
Pod undocumented
258 0 ▶sub getFlags { my ($self) = @_; return $$self[10]; }
Subroutine getFlags: not called CC=1 SCAR=6.9
Pod undocumented
259  
260 0 ▶sub toString {
Subroutine toString: not called CC=2 SCAR=17.9
Pod documented
261 0 my ($self) = @_;
262 0 ▶ return "Font[" . join(',', map { (defined $_ ? ToString($_) : '*') } @{$self}) . "]"; }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
263  
264 # Perhaps it is more useful to list only the non-default components?
265 0 ▶sub stringify {
Subroutine stringify: not called CC=12 SCAR=47.8
Pod documented
266 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
267 0 my ($self) = @_;
268 0 my ($fam, $ser, $shp, $siz, $col, $bkg, $opa, $enc, $lang, $mstyle, $flags) = @$self;
269 0 ▶ $fam = 'serif' if $fam && ($fam eq 'math');
Branch: 1 branch
BranchTrueFalseTotal
if $fam and $fam eq "math" 0 0 0
Condition0%0/3
$fam and $fam eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$fam and $fam eq "math"
$fam $fam eq "math"
Truth table0%0/3
A and B
A= $famB= $fam eq "math"
ABresult
0X0
100
111
270 0 ▶ return 'Font[' . join(',', map { Stringify($_) } grep { $_ }
Branch: 9 branches
BranchTrueFalseTotal
isDiff($fam, $DEFFAMILY) ? : 0 0 0
isDiff($ser, $DEFSERIES) ? : 0 0 0
isDiff($shp, $DEFSHAPE) ? : 0 0 0
isDiff($siz, DEFSIZE()) ? : 0 0 0
isDiff($col, $DEFCOLOR) ? : 0 0 0
isDiff($bkg, $DEFBACKGROUND) ? : 0 0 0
isDiff($opa, $DEFOPACITY) ? : 0 0 0
$mstyle ? : 0 0 0
$flags ? : 0 0 0
271 (isDiff($fam, $DEFFAMILY) ? ($fam) : ()),
272 (isDiff($ser, $DEFSERIES) ? ($ser) : ()),
273 (isDiff($shp, $DEFSHAPE) ? ($shp) : ()),
274 (isDiff($siz, DEFSIZE()) ? ($siz) : ()),
275 (isDiff($col, $DEFCOLOR) ? ($col) : ()),
276 (isDiff($bkg, $DEFBACKGROUND) ? ($bkg) : ()),
277 (isDiff($opa, $DEFOPACITY) ? ($opa) : ()),
278 ($mstyle ? ($mstyle) : ()),
279 ($flags ? ($flags) : ()),
280 )
281 . ']'; }
282  
283 0 ▶sub equals {
Subroutine equals: not called CC=5 SCAR=34.0
Pod documented
284 0 my ($self, $other) = @_;
285 return (defined $other) && ((ref $self) eq (ref $other))
286 0 ▶ && (join('|', map { (defined $_ ? $_ : '*') } @$self)
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
287 0 ▶ eq join('|', map { (defined $_ ? $_ : '*') } @$other)); }
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 0 0 0
Condition0%0/6
defined $other && ref $self eq ref $other && join('|', map({defined $_ ? $_ : '*';} @$self)) eq join('|', map({defined $_ ? $_ : '*';} @$other))
!ll&&!rl&&r
000
defined $other and ref $self eq ref $other
!ll&&!rl&&r
000
MC/DC0%0/3
defined $other && ref $self eq ref $other && join('|', map({defined $_ ? $_ : '*';} @$self)) eq join('|', map({defined $_ ? $_ : '*';} @$other))
defined $other ref $self eq ref $other join('|', map({defined $_ ? $_ : '*';} @$self)) eq join('|', map({defined $_ ? $_ : '*';} @$other))
Truth table0%0/4
A and B && C
A= defined $otherB= ref $self eq ref $otherC= join('|', map({defined $_ ? $_ : '*';} @$self)) eq join('|', map({defined $_ ? $_ : '*';} @$other))
ABCresult
0XX0
10X0
1100
1111
288  
289 0 ▶sub match {
Subroutine match: not called CC=7 SCAR=40.3
Pod undocumented
290 0 my ($self, $other) = @_;
291 0 ▶ return 1 unless defined $other;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $other 0 0 0
292 0 ▶ return 0 unless (ref $self) eq (ref $other);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq ref $other 0 0 0
293 0 my @comp = @$self;
294 0 my @ocomp = @$other;
295 # If any components are defined in both fonts, they must be equal.
296 0 ▶ while (@comp) {
Branch: 1 branch
BranchTrueFalseTotal
if (@comp) 0 0 0
297 0 my $c = shift @comp;
298 0 my $oc = shift @ocomp;
299 0 ▶ return 0 if (defined $c) && (defined $oc) && ($c ne $oc); }
Branch: 1 branch
BranchTrueFalseTotal
if defined $c and defined $oc and $c ne $oc 0 0 0
Condition0%0/6
defined $c and defined $oc and $c ne $oc
!ll&&!rl&&r
000
defined $c and defined $oc
!ll&&!rl&&r
000
MC/DC0%0/3
defined $c and defined $oc and $c ne $oc
defined $c defined $oc $c ne $oc
Truth table0%0/4
A and B and C
A= defined $cB= defined $ocC= $c ne $oc
ABCresult
0XX0
10X0
1100
1111
300 0 return 1; }
301  
302 0 ▶sub makeConcrete {
Subroutine makeConcrete: not called CC=13 SCAR=52.0
Pod undocumented
303 0 my ($self, $concrete) = @_;
304 0 my ($family, $series, $shape, $size, $color, $bg, $opacity, $encoding, $lang, $mstyle, $flags) = @$self;
305 0 my ($ofamily, $oseries, $oshape, $osize, $ocolor, $obg, $oopacity, $oencoding, $olang, $omstyle, $oflags) = @$concrete;
306 0 ▶ return (ref $self)->new_internal(
Branch: 1 branch
BranchTrueFalseTotal
defined $opacity ? : 0 0 0
Condition0%0/31
$family || $ofamily
l!l&&r!l&&!r
000
$series || $oseries
l!l&&r!l&&!r
000
$shape || $oshape
l!l&&r!l&&!r
000
$size || $osize
l!l&&r!l&&!r
000
$color || $ocolor
l!l&&r!l&&!r
000
$bg || $obg
l!l&&r!l&&!r
000
$encoding || $oencoding
l!l&&r!l&&!r
000
$lang || $olang
l!l&&r!l&&!r
000
$mstyle || $omstyle
l!l&&r!l&&!r
000
$flags || 0
l!l
00
$oflags || 0
l!l
00
MC/DC0%0/2
$family || $ofamily
$family $ofamily
MC/DC0%0/2
$series || $oseries
$series $oseries
MC/DC0%0/2
$shape || $oshape
$shape $oshape
MC/DC0%0/2
$size || $osize
$size $osize
MC/DC0%0/2
$color || $ocolor
$color $ocolor
MC/DC0%0/2
$bg || $obg
$bg $obg
MC/DC0%0/2
$encoding || $oencoding
$encoding $oencoding
MC/DC0%0/2
$lang || $olang
$lang $olang
MC/DC0%0/2
$mstyle || $omstyle
$mstyle $omstyle
MC/DC0%0/1
$flags || 0
$flags
MC/DC0%0/1
$oflags || 0
$oflags
Truth table0%0/3
A || B
A= $familyB= $ofamily
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $seriesB= $oseries
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $shapeB= $oshape
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $sizeB= $osize
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $colorB= $ocolor
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $bgB= $obg
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $encodingB= $oencoding
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $langB= $olang
ABresult
1X1
011
000
Truth table0%0/3
A || B
A= $mstyleB= $omstyle
ABresult
1X1
011
000
Truth table0%0/2
A
A= $flags
Aresult
11
00
Truth table0%0/2
A
A= $oflags
Aresult
11
00
307 $family || $ofamily, $series || $oseries, $shape || $oshape, $size || $osize,
308 $color || $ocolor, $bg || $obg, (defined $opacity ? $opacity : $oopacity),
309 $encoding || $oencoding, $lang || $olang, $mstyle || $omstyle,
310 ($flags || 0) | ($oflags || 0)); }
311  
312 0 ▶sub isDiff {
Subroutine isDiff: not called CC=3 SCAR=24.8
Pod undocumented
313 0 my ($x, $y) = @_;
314 0 ▶ return (defined $x) && (!(defined $y) || ($x ne $y)); }
Condition0%0/6
defined $x && (!defined($y) || $x ne $y)
!ll&&!rl&&r
000
not defined $y or $x ne $y
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $x && (!defined($y) || $x ne $y)
defined $x not defined $y $x ne $y
Truth table0%0/4
A && not(B) or C
A= defined $xB= not defined $yC= $x ne $y
ABCresult
0XX0
1000
11X1
1011
315  
316 # This method compares 2 fonts, returning the differences between them.
317 # Noting that the font-related attributes in the schema distill the
318 # font properties into fewer attributes (font,fontsize,color,background,opacity),
319 # the return value encodes both the attribute changes that would be needed to effect
320 # the font change, along with the font properties that differed
321 # Namely, the result is a hash keyed on the attribute name and whose value is a hash
322 # value => "new_attribute_value"
323 # properties => { %fontproperties }
324 # Note in particular 2 interesting keys
325 # element: can specify the element tagname to use for wrapping instead of ltx:text
326 # class: can be used to add a class attribute to the wrapping element
327 0 ▶sub relativeTo {
Subroutine relativeTo: not called CC=22 SCAR=62.3
Pod undocumented
328 0 my ($self, $other) = @_;
329 0 my ($fam, $ser, $shp, $siz, $col, $bkg, $opa, $enc, $lang, $mstyle, $flags) = @$self;
330 0 my ($ofam, $oser, $oshp, $osiz, $ocol, $obkg, $oopa, $oenc, $olang, $omstyle, $oflags) = @$other;
331 0 ▶ $fam = 'serif' if $fam && ($fam eq 'math');
Branch: 1 branch
BranchTrueFalseTotal
if $fam and $fam eq "math" 0 0 0
Condition0%0/3
$fam and $fam eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$fam and $fam eq "math"
$fam $fam eq "math"
Truth table0%0/3
A and B
A= $famB= $fam eq "math"
ABresult
0X0
100
111
332 0 ▶ $ofam = 'serif' if $ofam && ($ofam eq 'math');
Branch: 1 branch
BranchTrueFalseTotal
if $ofam and $ofam eq "math" 0 0 0
Condition0%0/3
$ofam and $ofam eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$ofam and $ofam eq "math"
$ofam $ofam eq "math"
Truth table0%0/3
A and B
A= $ofamB= $ofam eq "math"
ABresult
0X0
100
111
333 ## my $emph = 0;
334 ## $emph ||= $shp && $shp =~ s/^emph-//;
335 ## ## $emph ||= $oshp && $oshp =~ s/^emph-//;
336 ## $oshp && $oshp =~ s/^emph-//;
337 0 ▶ my @diffs = (
Branch: 3 branches
BranchTrueFalseTotal
isDiff($fam, $ofam) ? : 0 0 0
isDiff($ser, $oser) ? : 0 0 0
isDiff($shp, $oshp) ? : 0 0 0
338 (isDiff($fam, $ofam) ? ($fam) : ()),
339 (isDiff($ser, $oser) ? ($ser) : ()),
340 (isDiff($shp, $oshp) ? ($shp) : ()));
341 return (
342 0 ▶ (@diffs ?
Branch: 10 branches
BranchTrueFalseTotal
@diffs ? : 0 0 0
isDiff($fam, $ofam) ? : 0 0 0
isDiff($ser, $oser) ? : 0 0 0
isDiff($shp, $oshp) ? : 0 0 0
isDiff($siz, $osiz) ? : 0 0 0
isDiff($col, $ocol) ? : 0 0 0
isDiff($bkg, $obkg) ? : 0 0 0
isDiff($opa, $oopa) ? : 0 0 0
isDiff($lang, $olang) ? : 0 0 0
!$mstyle && $flags && $flags & $FLAG_EMPH && !($oflags && $oflags & $FLAG_EMPH) ? : 0 0 0
Condition0%0/12
not $mstyle and $flags and $flags & $FLAG_EMPH and not $oflags && $oflags & $FLAG_EMPH
!ll&&!rl&&r
000
not $mstyle and $flags and $flags & $FLAG_EMPH
!ll&&!rl&&r
000
not $mstyle and $flags
!ll&&!rl&&r
000
$oflags && $oflags & $FLAG_EMPH
!ll&&!rl&&r
000
MC/DC0%0/5
not $mstyle and $flags and $flags & $FLAG_EMPH and not $oflags && $oflags & $FLAG_EMPH
not $mstyle $flags $flags & $FLAG_EMPH $oflags $oflags & $FLAG_EMPH
Truth table0%0/6
not(A) and B and C and not(D && E)
A= not $mstyleB= $flagsC= $flags & $FLAG_EMPHD= $oflagsE= $oflags & $FLAG_EMPH
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
343 (font => { value => join(' ', @diffs),
344 properties => { (isDiff($fam, $ofam) ? (family => $fam) : ()),
345 (isDiff($ser, $oser) ? (series => $ser) : ()),
346 (isDiff($shp, $oshp) ? (shape => $shp) : ()) } })
347 : ()),
348 (isDiff($siz, $osiz)
349 ### ? (fontsize => { value => $siz, properties => { size => $siz } })
350 ? (fontsize => { value => relativeFontSize($siz, $osiz), properties => { size => $siz } })
351 : ()),
352 (isDiff($col, $ocol)
353 ? (color => { value => $col, properties => { color => $col } })
354 : ()),
355 (isDiff($bkg, $obkg)
356 ? (backgroundcolor => { value => $bkg, properties => { background => $bkg } })
357 : ()),
358 (isDiff($opa, $oopa)
359 ? (opacity => { value => $opa, properties => { opacity => $opa } })
360 : ()),
361 (isDiff($lang, $olang)
362 ? ('xml:lang' => { value => $lang, properties => { language => $lang } })
363 : ()),
364 (!$mstyle && $flags && ($flags & $FLAG_EMPH) && (!$oflags || !($oflags & $FLAG_EMPH))
365 ? (
366 # class => { value => 'ltx_emph' },
367 element => { value => 'ltx:emph' }
368 )
369 : ()),
370 ### Contemplate this: We do NOT want mathstyle showing up (automatically) in the attributes
371 ### So, we presumably want to ignore differences in mathstyle
372 ### They shouldn't (by themselves) affect the display?
373 ### (isDiff($mstyle, $omstyle)
374 ### ? ('mathstyle' => { value => $mstyle, properties => { mathstyle => $mstyle } })
375 ### : ()),
376 ); }
377  
378 0 ▶sub distance {
Subroutine distance: not called CC=14 SCAR=53.5
Pod undocumented
379 0 my ($self, $other) = @_;
380 0 my ($fam, $ser, $shp, $siz, $col, $bkg, $opa, $enc, $lang, $mstyle, $flags) = @$self;
381 0 my ($ofam, $oser, $oshp, $osiz, $ocol, $obkg, $oopa, $oenc, $olang, $omstyle, $oflags) = @$other;
382 0 ▶ $fam = 'serif' if $fam && ($fam eq 'math');
Branch: 1 branch
BranchTrueFalseTotal
if $fam and $fam eq "math" 0 0 0
Condition0%0/3
$fam and $fam eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$fam and $fam eq "math"
$fam $fam eq "math"
Truth table0%0/3
A and B
A= $famB= $fam eq "math"
ABresult
0X0
100
111
383 0 ▶ $ofam = 'serif' if $ofam && ($ofam eq 'math');
Branch: 1 branch
BranchTrueFalseTotal
if $ofam and $ofam eq "math" 0 0 0
Condition0%0/3
$ofam and $ofam eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$ofam and $ofam eq "math"
$ofam $ofam eq "math"
Truth table0%0/3
A and B
A= $ofamB= $ofam eq "math"
ABresult
0X0
100
111
384 return
385 0 ▶ (isDiff($fam, $ofam) ? 1 : 0)
Branch: 9 branches
BranchTrueFalseTotal
isDiff($fam, $ofam) ? : 0 0 0
isDiff($ser, $oser) ? : 0 0 0
isDiff($shp, $oshp) ? : 0 0 0
isDiff($siz, $osiz) ? : 0 0 0
isDiff($col, $ocol) ? : 0 0 0
isDiff($bkg, $obkg) ? : 0 0 0
isDiff($opa, $oopa) ? : 0 0 0
isDiff($lang, $olang) ? : 0 0 0
$flags & $FLAG_EMPH ^ $oflags & $FLAG_EMPH ? : 0 0 0
386 + (isDiff($ser, $oser) ? 1 : 0)
387 + (isDiff($shp, $oshp) ? 1 : 0)
388 + (isDiff($siz, $osiz) ? 1 : 0)
389 + (isDiff($col, $ocol) ? 1 : 0)
390 + (isDiff($bkg, $obkg) ? 1 : 0)
391 + (isDiff($opa, $oopa) ? 1 : 0)
392 ## + (isDiff($enc,$oenc) ? 1 : 0)
393 + (isDiff($lang, $olang) ? 1 : 0)
394 # Let's not consider mathstyle differences here, either.
395 ### + (isDiff($mstyle, $omstyle) ? 1 : 0)
396 + (($flags & $FLAG_EMPH) ^ ($oflags & $FLAG_EMPH) ? 1 : 0)
397 ; }
398  
399 # This matches fonts when both are converted to strings (toString),
400 # such as when they are set as attributes.
401 # This accumulates regular expressions used by match_font
402 # (which, in turn, is used in various XPath searches!)
403 # It is NOT really Daemon safe....
404 # Need to work out how to do this and/or cache it in STATE????
405 5 our %FONT_REGEXP_CACHE = ();
406  
407 0 ▶sub match_font {
Subroutine match_font: not called CC=4 SCAR=30.0
Pod undocumented
408 0 my ($font1, $font2) = @_;
409 0 my $regexp = $FONT_REGEXP_CACHE{$font1};
410 0 ▶ if (!$regexp) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($regexp) 0 0 0
411 0 ▶ if ($font1 =~ /^Font\[(.*)\]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font1 =~ /^Font\[(.*)\]$/) 0 0 0
412 0 my @comp = split(',', $1);
413 my $re = '^Font\['
414 0 ▶ . join(',', map { ($_ eq '*' ? "[^,]+" : "\Q$_\E") } @comp)
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '*' ? : 0 0 0
415 . '\]$';
416 0 $regexp = $FONT_REGEXP_CACHE{$font1} = qr/$re/; } }
417 0 return $font2 =~ /$regexp/; }
418  
419 0 ▶sub XXXfont_match_xpaths {
Subroutine XXXfont_match_xpaths: not called CC=9 SCAR=45.0
Pod undocumented
420 0 my ($font) = @_;
421 0 ▶ if ($font =~ /^Font\[(.*)\]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font =~ /^Font\[(.*)\]$/) 0 0 0
422 0 my @comps = split(',', $1);
423 0 my ($frag, @frags) = ();
424 0 ▶ for (my $i = 0 ; $i <= $#comps ; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $#comps) 0 0 0
425 0 my $comp = $comps[$i];
426 0 ▶ if ($comp eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($comp eq '*') { } 0 0 0
427 0 ▶ push(@frags, $frag) if $frag;
Branch: 1 branch
BranchTrueFalseTotal
if $frag 0 0 0
428 0 $frag = undef; }
429 else {
430 0 ▶ my $post = ($i == $#comps ? ']' : ',');
Branch: 1 branch
BranchTrueFalseTotal
$i == $#comps ? : 0 0 0
431 0 ▶ if ($frag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($frag) { } 0 0 0
432 0 $frag .= $comp . $post; }
433 else {
434 0 ▶ $frag = ($i == 0 ? 'Font[' : ',') . $comp . $post; } } }
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 0 0 0
435 0 ▶ push(@frags, $frag) if $frag;
Branch: 1 branch
BranchTrueFalseTotal
if $frag 0 0 0
436 return join(' and ', '@_font',
437 0 map { "contains(\@_font,'$_')" } @frags); } }
438  
439 0 ▶sub font_match_xpaths {
Subroutine font_match_xpaths: not called CC=5 SCAR=34.0
Pod undocumented
440 0 my ($font) = @_;
441 0 ▶ if ($font =~ /^Font\[(.*)\]$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($font =~ /^Font\[(.*)\]$/) 0 0 0
442 0 my ($family, $series, $shape, $size, $color, $bg, $opacity, $encoding, $language,
443 $mstyle, $force) = split(',', $1);
444 # Ignore differences in:
445 # size, background, opacity, encoding, language(?), mathstyle,
446 # force bits assumed NOT relevant, also.
447 # For now, ignore color, too
448 0 my @frags = ();
449 0 ▶ push(@frags, '[' . $family . ',') if ($family ne '*');
Branch: 1 branch
BranchTrueFalseTotal
if $family ne "*" 0 0 0
450 0 ▶ push(@frags, ',' . $series . ',') if ($series ne '*');
Branch: 1 branch
BranchTrueFalseTotal
if $series ne "*" 0 0 0
451 0 ▶ push(@frags, ',' . $shape . ',') if ($shape ne '*');
Branch: 1 branch
BranchTrueFalseTotal
if $shape ne "*" 0 0 0
452 # push(@frags, ',' . $color . ',') if ($color ne '*');
453 return join(' and ', '@_font',
454 0 map { "contains(\@_font,'$_')" } @frags); } }
455  
456 # # Presumably a text font is "sticky", if used in math?
457 # sub isSticky { return 1; }
458  
459 # Probably needs to account for what unicode char we're looking for;
460 # and whether we are in math mode, along with whatever other font properties we want
461 5 my @textfonts = (qw(cmr cmm cmsy cmex amsa amsb));
462 5 my @mathfonts = (qw(cmm cmsy cmex amsa amsb cmr));
463  
464 0 ▶sub getMetric {
Subroutine getMetric: not called CC=5 SCAR=34.0
Pod undocumented
465 0 my ($self, $char) = @_;
466 0 ▶ if (defined $char) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $char) 0 0 0
467 0 ▶ my @fonts = ($self->getFamily eq 'math' ? @mathfonts : @textfonts);
Branch: 1 branch
BranchTrueFalseTotal
$self->getFamily eq 'math' ? : 0 0 0
468 0 foreach my $name (@fonts) {
469 0 my $m = $$LaTeXML::Common::Font::StandardMetrics::STDMETRICS{$name};
470 0 ▶ return $m if $$m{sizes}{$char}; } }
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"sizes"}{$char} 0 0 0
471 0 return $$LaTeXML::Common::Font::StandardMetrics::STDMETRICS{cmr}; }
472  
473 ## get sizes, get kerns....
474  
475 #======================================================================
476 5 our %mathstylesize = (display => 1, text => 1,
477 script => 0.7, scriptscript => 0.5);
478  
479 0 ▶sub getEMWidth {
Subroutine getEMWidth: not called CC=3 SCAR=24.8
Pod undocumented
480 0 my ($self) = @_;
481 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10);
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
482 # Could (should) look for metric w/appropriate slant, weight, etc
483 0 my $m = $$LaTeXML::Common::Font::StandardMetrics::STDMETRICS{cmr};
484 0 return int($size * $$m{emwidth}); }
485  
486 0 ▶sub getEXHeight {
Subroutine getEXHeight: not called CC=3 SCAR=24.8
Pod undocumented
487 0 my ($self) = @_;
488 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10);
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
489 # Could (should) look for metric w/appropriate slant, weight, etc
490 0 my $m = $$LaTeXML::Common::Font::StandardMetrics::STDMETRICS{cmr};
491 0 return int($size * $$m{exheight}); }
492  
493 0 ▶sub getMUWidth {
Subroutine getMUWidth: not called CC=3 SCAR=24.8
Pod undocumented
494 0 my ($self) = @_;
495 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10);
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
496 0 my $m = $$LaTeXML::Common::Font::StandardMetrics::STDMETRICS{cmm};
497 0 return int($size * $$m{emwidth} / 18); }
498  
499 # NOTE: that we assume the size has already been adjusted for mathstyle, if necessary.
500 0 ▶sub computeStringSize {
Subroutine computeStringSize: not called CC=13 SCAR=52.0
Pod undocumented
501 0 my ($self, $string) = @_;
502 0 ▶ if ((!defined $string) || ($string eq '') || ($self->getFamily eq 'nullfont')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $string or $string eq "" or $self->getFamily eq "nullfont") 0 0 0
Condition0%0/6
not defined $string or $string eq "" or $self->getFamily eq "nullfont"
l!l&&r!l&&!r
000
not defined $string or $string eq ""
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $string or $string eq "" or $self->getFamily eq "nullfont"
not defined $string $string eq "" $self->getFamily eq "nullfont"
Truth table0%0/4
not(A) or B or C
A= not defined $stringB= $string eq ""C= $self->getFamily eq "nullfont"
ABCresult
1XX1
01X1
0011
0000
503 0 return (Dimension(0), Dimension(0), Dimension(0)); }
504 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10); ## * $mathstylesize{ $self->getMathstyle || 'text' };
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
505 0 my $ismath = $self->getFamily eq 'math';
506 0 my ($w, $h, $d) = (0, 0, 0);
507 0 my @chars = split(//, $string);
508 0 ▶ while (@chars) {
Branch: 1 branch
BranchTrueFalseTotal
if (@chars) 0 0 0
509 0 my $char = shift(@chars);
510 0 my $metric = $self->getMetric($char);
511 0 my $entry = $$metric{sizes}{$char};
512 ## Debug("No size entry for '$char' (" . sprintf("%x", ord($char)) . ")") unless $entry;
513 0 ▶ my ($cw, $ch, $cd, $ci) = ($entry ? @$entry : (0.75 * $UNITY, 0.7 * $UNITY, 0.2 * $UNITY, 0));
Branch: 1 branch
BranchTrueFalseTotal
$entry ? : 0 0 0
514 0 $w += int($cw * $size);
515 0 ▶ if (my $kern = $chars[0] && $$metric{kerns}{ $char . $chars[0] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $kern = $chars[0] && $metric->{"kerns"}{$char . $chars[0]}) 0 0 0
Condition0%0/3
$chars[0] && $metric->{'kerns'}{$char . $chars[0]}
!ll&&!rl&&r
000
MC/DC0%0/2
$chars[0] && $metric->{'kerns'}{$char . $chars[0]}
$chars[0] $metric->{'kerns'}{$char . $chars[0]}
Truth table0%0/3
A && B
A= $chars[0]B= $metric->{'kerns'}{$char . $chars[0]}
ABresult
0X0
100
111
516 0 $w += int($size * $kern); }
517 0 ▶ if ($ismath && $ci) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ismath and $ci) 0 0 0
Condition0%0/3
$ismath and $ci
!ll&&!rl&&r
000
MC/DC0%0/2
$ismath and $ci
$ismath $ci
Truth table0%0/3
A and B
A= $ismathB= $ci
ABresult
0X0
100
111
518 0 $w += int($size * $ci); }
519 0 $h = max($h, int($ch * $size));
520 0 $d = max($d, int($cd * $size)); }
521 # The 1 is so that any actual glyph appears to be non-empty.
522 # This is presumably only necessary to deal with the flawed emptiness heiristics in Alignment?
523 0 ▶ return (Dimension(int($w || 1)), Dimension(int($h)), Dimension(int($d))); }
Condition0%0/2
$w || 1
l!l
00
MC/DC0%0/1
$w || 1
$w
Truth table0%0/2
A
A= $w
Aresult
11
00
524  
525 # Get nominal width, height base ?
526 # Probably should be using data from FontMetric ???
527 0 ▶sub getNominalSize {
Subroutine getNominalSize: not called CC=3 SCAR=24.8
Pod undocumented
528 0 my ($self) = @_;
529 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10); ## * $mathstylesize{ $self->getMathstyle || 'text' };
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
530 0 my $u = $size * $UNITY;
531 0 return (Dimension(0.75 * $u), Dimension(0.7 * $u), Dimension(0.2 * $u)); }
532  
533 # Here's where I avoid trying to emulate Knuth's line-breaking...
534 # Mostly for List & Whatsit: compute the size of a list of boxes.
535 # Options _SHOULD_ include:
536 # width: if given, pretend to simulate line breaking to that width
537 # height,depth : ?
538 # vattach : top, bottom, center, baseline (...?) affects how the height & depth are
539 # allocated when there are multiple lines.
540 # layout : horizontal or vertical !!!
541 # Boxes that arent a Core Box, List, Whatsit or a string are IGNORED
542 #
543 # The big problem with width is to have it propogate down from where
544 # it may have been specified to the actual nested box that will get wrapped!
545 # Try to mask this (temporarily) by unlisting, and (pretending to ) breaking up too wide items
546 #
547 # Another issue; SVG needs (sometimes) real sizes, even if the programmer
548 # set some dimensions to 0 (eg.) We may need to distinguish & store
549 # requested vs real sizes?
550 0 ▶sub computeBoxesSize {
Subroutine computeBoxesSize: not called CC=49 SCAR=77.6
Pod undocumented
551 0 my ($self, $boxes, %options) = @_;
552 0 ▶ my $font = (ref $self ? $self : $STATE->lookupValue('font'));
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 0 0 0
553 0 my $fillwidth = $options{width};
554 0 ▶ if ((!defined $fillwidth) && ($fillwidth = $STATE->lookupDefinition(T_CS('\textwidth')))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $fillwidth and $fillwidth = $LaTeXML::Common::Font::STATE->lookupDefinition(T_CS("\\textwidth"))) 0 0 0
Condition0%0/3
not defined $fillwidth and $fillwidth = $LaTeXML::Common::Font::STATE->lookupDefinition(T_CS("\\textwidth"))
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $fillwidth and $fillwidth = $LaTeXML::Common::Font::STATE->lookupDefinition(T_CS("\\textwidth"))
not defined $fillwidth $fillwidth = $LaTeXML::Common::Font::STATE->lookupDefinition(T_CS("\\textwidth"))
Truth table0%0/3
not(A) and B
A= not defined $fillwidthB= $fillwidth = $LaTeXML::Common::Font::STATE->lookupDefinition(T_CS("\\textwidth"))
ABresult
0X0
100
111
555 0 $fillwidth = $fillwidth->valueOf; } # get register
556 0 ▶ my $maxwidth = $fillwidth && $fillwidth->valueOf;
Condition0%0/3
$fillwidth && $fillwidth->valueOf
!ll&&!rl&&r
000
MC/DC0%0/2
$fillwidth && $fillwidth->valueOf
$fillwidth $fillwidth->valueOf
Truth table0%0/3
A && B
A= $fillwidthB= $fillwidth->valueOf
ABresult
0X0
100
111
557 # baselineskip, lineskip ??
558 0 my $baseline = $STATE->lookupDefinition(T_CS('\baselineskip'))->valueOf->valueOf;
559 0 my $lineskip = $STATE->lookupDefinition(T_CS('\lineskip'))->valueOf->valueOf;
560 0 my @lines = ();
561 0 my ($wd, $ht, $dp) = (0, 0, 0);
562 0 my ($minwd, $minht, $mindp) = (0, 0, 0);
563 0 ▶ my $vattach = $options{vattach} || 'baseline';
Condition0%0/2
$options{'vattach'} || 'baseline'
l!l
00
MC/DC0%0/1
$options{'vattach'} || 'baseline'
$options{'vattach'}
Truth table0%0/2
A
A= $options{'vattach'}
Aresult
11
00
564 5 ▶ no warnings 'recursion';
Subroutine BEGIN: called CC=1 SCAR=0.0
565 # Flatten top-level Lists (orrr pass-thru $fillwidth ???)
566 # my @boxes = map { (ref $_ eq 'LaTeXML::Core::List' ? $_->unlist : $_); } @$boxes;
567 0 ▶ my @boxes = grep { !(ref $_) || !$_->getProperty('isEmpty') }
Condition0%0/3
ref $_ && $_->getProperty('isEmpty')
!ll&&!rl&&r
000
MC/DC0%0/2
ref $_ && $_->getProperty('isEmpty')
ref $_ $_->getProperty('isEmpty')
Truth table0%0/3
A && B
A= ref $_B= $_->getProperty('isEmpty')
ABresult
0X0
100
111
568 0 ▶ map { (ref $_ eq 'LaTeXML::Core::List' ? $_->unlist : $_); }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'LaTeXML::Core::List' ? : 0 0 0
569 0 ▶ grep { !(ref $_) || $_->can('getSize'); } @$boxes;
Condition0%0/3
!ref($_) || $_->can('getSize')
l!l&&r!l&&!r
000
MC/DC0%0/2
!ref($_) || $_->can('getSize')
!ref($_) $_->can('getSize')
Truth table0%0/3
not(A) || B
A= !ref($_)B= $_->can('getSize')
ABresult
1X1
011
000
570 0 my $prevbox;
571 # foreach my $box (@boxes) {
572 0 ▶ while (@boxes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@boxes) 0 0 0
573 0 my $box = shift(@boxes);
574 0 ▶ next unless defined $box;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $box 0 0 0
575 0 ▶ next if ref $box && !$box->can('getSize'); # Care!! Since we're asking ALL args/compoments
Branch: 1 branch
BranchTrueFalseTotal
if ref $box and not $box->can("getSize") 0 0 0
Condition0%0/3
ref $box and not $box->can("getSize")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $box and not $box->can("getSize")
ref $box not $box->can("getSize")
Truth table0%0/3
A and not(B)
A= ref $boxB= not $box->can("getSize")
ABresult
0X0
100
111
576 # next if ref $box && $box->getProperty('isEmpty');
577 ## Should any %options be inherited by the contained boxes?
578 0 ▶ my ($w, $h, $d) = (ref $box ? $box->getSize() : $font->computeStringSize($box));
Branch: 1 branch
BranchTrueFalseTotal
ref $box ? : 0 0 0
579 0 ▶ if ((ref $w) && $w->can('_unit')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $w and $w->can('_unit')) { } 0 0 0
Condition0%0/3
ref $w and $w->can("_unit")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $w and $w->can("_unit")
ref $w $w->can("_unit")
Truth table0%0/3
A and B
A= ref $wB= $w->can("_unit")
ABresult
0X0
100
111
580 0 ▶ $wd += ($w->_unit eq 'mu' ? $w->spValue : $w->valueOf); }
Branch: 1 branch
BranchTrueFalseTotal
$w->_unit eq 'mu' ? : 0 0 0
581 else {
582 0 Warn('expected', 'Dimension', undef,
583 "Width of " . Stringify($box) . " yielded a non-dimension: " . Stringify($w)); }
584 0 ▶ if ((ref $h) && $h->can('_unit')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $h and $h->can('_unit')) { } 0 0 0
Condition0%0/3
ref $h and $h->can("_unit")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $h and $h->can("_unit")
ref $h $h->can("_unit")
Truth table0%0/3
A and B
A= ref $hB= $h->can("_unit")
ABresult
0X0
100
111
585 0 ▶ $ht = max($ht, ($h->_unit eq 'mu' ? $h->spValue : $h->valueOf)); }
Branch: 1 branch
BranchTrueFalseTotal
$h->_unit eq 'mu' ? : 0 0 0
586 else {
587 0 Warn('expected', 'Dimension', undef,
588 "Height of " . Stringify($box) . " yielded a non-dimension: " . Stringify($h)); }
589 0 ▶ if ((ref $d) && $d->can('_unit')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $d and $d->can('_unit')) { } 0 0 0
Condition0%0/3
ref $d and $d->can("_unit")
!ll&&!rl&&r
000
MC/DC0%0/2
ref $d and $d->can("_unit")
ref $d $d->can("_unit")
Truth table0%0/3
A and B
A= ref $dB= $d->can("_unit")
ABresult
0X0
100
111
590 0 ▶ $dp = max($dp, ($d->_unit eq 'mu' ? $d->spValue : $d->valueOf)); }
Branch: 1 branch
BranchTrueFalseTotal
$d->_unit eq 'mu' ? : 0 0 0
591 else {
592 0 Warn('expected', 'Dimension', undef,
593 "Depth of " . Stringify($box) . " yielded a non-dimension: " . Stringify($d)); }
594 # Kern HACK for lists of individual Box's
595 0 ▶ if ($prevbox && (ref $prevbox eq 'LaTeXML::Core::Box') && (ref $box eq 'LaTeXML::Core::Box')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prevbox and ref $prevbox eq "LaTeXML::Core::Box" and ref $box eq "LaTeXML::Core::Box") 0 0 0
Condition0%0/6
$prevbox and ref $prevbox eq "LaTeXML::Core::Box" and ref $box eq "LaTeXML::Core::Box"
!ll&&!rl&&r
000
$prevbox and ref $prevbox eq "LaTeXML::Core::Box"
!ll&&!rl&&r
000
MC/DC0%0/3
$prevbox and ref $prevbox eq "LaTeXML::Core::Box" and ref $box eq "LaTeXML::Core::Box"
$prevbox ref $prevbox eq "LaTeXML::Core::Box" ref $box eq "LaTeXML::Core::Box"
Truth table0%0/4
A and B and C
A= $prevboxB= ref $prevbox eq "LaTeXML::Core::Box"C= ref $box eq "LaTeXML::Core::Box"
ABCresult
0XX0
10X0
1100
1111
596 0 ▶ my $prevchar = substr($prevbox->getString || '', -1, 1);
Condition0%0/2
$prevbox->getString || ''
l!l
00
MC/DC0%0/1
$prevbox->getString || ''
$prevbox->getString
Truth table0%0/2
A
A= $prevbox->getString
Aresult
11
00
597 0 ▶ my $curchar = substr($box->getString || '', 0, 1);
Condition0%0/2
$box->getString || ''
l!l
00
MC/DC0%0/1
$box->getString || ''
$box->getString
Truth table0%0/2
A
A= $box->getString
Aresult
11
00
598 0 my $metric = $self->getMetric($curchar);
599 0 ▶ if ($prevbox && ($self->getFamily eq 'math')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prevbox and $self->getFamily eq "math") 0 0 0
Condition0%0/3
$prevbox and $self->getFamily eq "math"
!ll&&!rl&&r
000
MC/DC0%0/2
$prevbox and $self->getFamily eq "math"
$prevbox $self->getFamily eq "math"
Truth table0%0/3
A and B
A= $prevboxB= $self->getFamily eq "math"
ABresult
0X0
100
111
600 0 $wd += $self->math_bearing($box, $prevbox); }
601 0 ▶ if (my $kern = $$metric{kerns}{ $prevchar . $curchar }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $kern = $metric->{"kerns"}{$prevchar . $curchar}) 0 0 0
602 0 ▶ my $size = ($self->getSize || DEFSIZE() || 10); ## * $mathstylesize{ $self->getMathstyle || 'text' };
Condition0%0/5
$self->getSize || DEFSIZE() || 10
l!l
00
$self->getSize or DEFSIZE()
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->getSize || DEFSIZE() || 10
$self->getSize DEFSIZE()
Truth table0%0/3
A or B
A= $self->getSizeB= DEFSIZE()
ABresult
1X1
011
000
603 0 $wd += $size * $kern; } }
604  
605 0 ▶ my $newline = (($options{layout} || '') eq 'vertical') # EVERY box is a row?
Condition0%0/14
($options{'layout'} || '') eq 'vertical' || ref $box && $box->getProperty('isBreak') || defined $maxwidth && $wd >= $maxwidth
l!l&&r!l&&!r
000
($options{"layout"} || "") eq "vertical" or ref $box and $box->getProperty("isBreak")
l!l&&r!l&&!r
000
$options{'layout'} || ''
l!l
00
ref $box and $box->getProperty("isBreak")
!ll&&!rl&&r
000
defined $maxwidth and $wd >= $maxwidth
!ll&&!rl&&r
000
MC/DC0%0/5
($options{'layout'} || '') eq 'vertical' || ref $box && $box->getProperty('isBreak') || defined $maxwidth && $wd >= $maxwidth
$options{'layout'} ref $box $box->getProperty("isBreak") defined $maxwidth $wd >= $maxwidth
Truth table0%0/8
A or B and C || D and E
A= $options{'layout'}B= ref $boxC= $box->getProperty("isBreak")D= defined $maxwidthE= $wd >= $maxwidth
ABCDEresult
1XXXX1
011XX1
00X111
010111
00X0X0
00X100
0100X0
010100
606 || ((ref $box) && $box->getProperty('isBreak')) # || $box is a linebreak
607 || ((defined $maxwidth) && ($wd >= $maxwidth)); # or we've reached the requested width
608 0 ▶ if ($newline) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newline) 0 0 0
609 0 ▶ if (@boxes) {
Branch: 1 branch
BranchTrueFalseTotal
if (@boxes) 0 0 0
610 0 ▶ if ($baseline > $ht + $dp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($baseline > $ht + $dp) { } 0 0 0
611 0 $dp = $baseline - $ht; }
612 else {
613 0 $dp += $lineskip; } }
614 0 push(@lines, [$wd, $ht, $dp]); $wd = $ht = $dp = 0; }
615 0 $prevbox = $box; }
616 0 ▶ if ($wd || $ht || $dp) { # be sure to get last line
Branch: 1 branch
BranchTrueFalseTotal
if ($wd or $ht or $dp) 0 0 0
Condition0%0/6
$wd or $ht or $dp
l!l&&r!l&&!r
000
$wd or $ht
l!l&&r!l&&!r
000
MC/DC0%0/3
$wd or $ht or $dp
$wd $ht $dp
Truth table0%0/4
A or B or C
A= $wdB= $htC= $dp
ABCresult
1XX1
01X1
0011
0000
617 0 push(@lines, [$wd, $ht, $dp]); }
618 # Deal with multiple lines
619 0 my $nlines = scalar(@lines);
620 0 ▶ if ($nlines == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($nlines == 0) { } 0 0 0
621 0 $wd = $ht = $dp = 0; }
622 else {
623 0 $wd = max(map { $$_[0] } @lines);
624 0 $ht = sum(map { $$_[1] } @lines);
625 0 $dp = sum(map { $$_[2] } @lines);
626 0 ▶ if ($vattach eq 'top') { # Top of box is aligned with top(?) of current text
Branch: 3 branches
BranchTrueFalseTotal
if ($vattach eq 'top') { } 0 0 0
elsif ($vattach eq 'bottom') { } 0 0 0
elsif ($vattach eq 'middle') { } 0 0 0
627 0 my ($w, $h, $d) = $font->getNominalSize;
628 0 $h = $h->valueOf;
629 0 $dp = $ht + $dp - $h; $ht = $h; }
630 elsif ($vattach eq 'bottom') { # Bottom of box is aligned with bottom (?) of current text
631 0 $ht = $ht + $dp; $dp = 0; }
632 elsif ($vattach eq 'middle') {
633 0 my ($w, $h, $d) = $font->getNominalSize;
634 0 $h = $h->valueOf;
635 0 my $c = ($ht + $dp) / 2;
636 0 $ht = $c + $h / 2; $dp = $c - $h / 2; }
637 else { # default is baseline (of the 1st line)
638 0 my $h = $lines[0][1];
639 0 $dp = $ht + $dp - $h; $ht = $h; } }
640 ### $wd = max($minwd, $wd); $ht = max($minht, $ht); $dp = max($mindp, $dp);
641 0 Debug("Size boxes " . join(',', map { $_ . '=' . ToString($options{$_}); } sort keys %options) . "\n"
642 0 . " Boxes: " . join(',', map { '[[' . ToString($_) . ']]'; } @$boxes) . "\n"
643 0 . " Sizes: " . join("\n", map { _showsize(@$_); } @lines) . "\n"
644 0 ▶ . " => " . _showsize($wd, $ht, $dp)) if $LaTeXML::DEBUG{'size-detailed'};
Branch: 1 branch
BranchTrueFalseTotal
if $LaTeXML::DEBUG{"size-detailed"} 0 0 0
645 0 return (Dimension($wd), Dimension($ht), Dimension($dp)); }
646  
647 # Probably a clumsy way of dealing with math spacing...
648 # 0=Ord, 1=Op, 2=Bin, 3=Rel, 4=Open, 5=Close, 6=Punct, 7=Inner
649 5 my %mathatomtype = (ID => 0,
650 BIGOP => 1, SUMOP => 1, INTOP => 1, OPERATOR => 1, LIMITOP => 1, DIFFOP => 1,
651 ADDOP => 2, MULOP => 2, BINOP => 2, COMPOSEOP => 2, MIDDLE => 2, VERTBAR => 2,
652 RELOP => 3, METARELOP => 3, ARROW => 3,
653 OPEN => 4, CLOSE => 5,
654 PUNCT => 6, PERIOD => 6,
655 ARRAY => 7, MODIFIER => 7);
656 # mysterious: MODIFIEROP, POSTFIX, APPLYOP, SUPOP
657 5 my $mathbearings = [
658 [0, 1, -2, -3, 0, 0, 0, -1],
659 [1, 1, 0, -3, 0, 0, 0, -1],
660 [-2, -2, 0, 0, -2, 0, 0, -2],
661 [-3, -3, 0, 0, -3, 0, 0, -3],
662 [0, 0, 0, 0, 0, 0, 0, 0],
663 [0, 1, -2, -3, 0, 0, 0, -1],
664 [-1, -1, 0, -1, -1, -1, -1, -1],
665 [-1, 1, -2, -3, -1, 0, -1, -1]];
666 5 my $mathbearingreg = [undef, T_CS('\thinmuskip'), T_CS('\medmuskip'), T_CS('\thickmuskip')];
667  
668 0 ▶sub math_bearing {
Subroutine math_bearing: not called CC=10 SCAR=47.0
Pod undocumented
669 0 my ($self, $box, $prevbox) = @_;
670 0 ▶ my $r0 = $prevbox->getProperty('role') || 'ID';
Condition0%0/2
$prevbox->getProperty('role') || 'ID'
l!l
00
MC/DC0%0/1
$prevbox->getProperty('role') || 'ID'
$prevbox->getProperty('role')
Truth table0%0/2
A
A= $prevbox->getProperty('role')
Aresult
11
00
671 0 ▶ my $r1 = $box->getProperty('role') || 'ID';
Condition0%0/2
$box->getProperty('role') || 'ID'
l!l
00
MC/DC0%0/1
$box->getProperty('role') || 'ID'
$box->getProperty('role')
Truth table0%0/2
A
A= $box->getProperty('role')
Aresult
11
00
672 0 ▶ my $t0 = $mathatomtype{$r0} || 0;
Condition0%0/2
$mathatomtype{$r0} || 0
l!l
00
MC/DC0%0/1
$mathatomtype{$r0} || 0
$mathatomtype{$r0}
Truth table0%0/2
A
A= $mathatomtype{$r0}
Aresult
11
00
673 0 ▶ my $t1 = $mathatomtype{$r1} || 0;
Condition0%0/2
$mathatomtype{$r1} || 0
l!l
00
MC/DC0%0/1
$mathatomtype{$r1} || 0
$mathatomtype{$r1}
Truth table0%0/2
A
A= $mathatomtype{$r1}
Aresult
11
00
674 0 my $bearing = $$mathbearings[$t0][$t1];
675 0 ▶ my $style = $self->getMathstyle || 'text';
Condition0%0/2
$self->getMathstyle || 'text'
l!l
00
MC/DC0%0/1
$self->getMathstyle || 'text'
$self->getMathstyle
Truth table0%0/2
A
A= $self->getMathstyle
Aresult
11
00
676 0 ▶ if (!$bearing || (($bearing < 0) && ($style ne 'display') && ($style ne 'text'))) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $bearing or $bearing < 0 and $style ne "display" and $style ne "text") 0 0 0
Condition0%0/9
not $bearing or $bearing < 0 and $style ne "display" and $style ne "text"
l!l&&r!l&&!r
000
$bearing < 0 and $style ne "display" and $style ne "text"
!ll&&!rl&&r
000
$bearing < 0 and $style ne "display"
!ll&&!rl&&r
000
MC/DC0%0/4
not $bearing or $bearing < 0 and $style ne "display" and $style ne "text"
not $bearing $bearing < 0 $style ne "display" $style ne "text"
Truth table0%0/5
not(A) or B and C and D
A= not $bearingB= $bearing < 0C= $style ne "display"D= $style ne "text"
ABCDresult
1XXX1
01111
00XX0
010X0
01100
677 0 return 0; }
678 0 return $STATE->lookupDefinition($$mathbearingreg[abs($bearing)])->valueOf->spValue; }
679  
680 0 ▶sub _showsize {
Subroutine _showsize: not called CC=1 SCAR=6.9
681 0 my ($wd, $ht, $dp) = @_;
682 0 return ($wd / $UNITY) . " x " . ($ht / $UNITY) . " + " . ($dp / $UNITY); }
683  
684 0 ▶sub isSticky {
Subroutine isSticky: not called CC=2 SCAR=17.9
Pod undocumented
685 0 my ($self) = @_;
686 0 ▶ return $$self[0] && ($$self[0] =~ /^(?:serif|sansserif|typewriter)$/); }
Condition0%0/3
$self->[0] && $self->[0] =~ /^(?:serif|sansserif|typewriter)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->[0] && $self->[0] =~ /^(?:serif|sansserif|typewriter)$/
$self->[0] $self->[0] =~ /^(?:serif|sansserif|typewriter)$/
Truth table0%0/3
A && B
A= $self->[0]B= $self->[0] =~ /^(?:serif|sansserif|typewriter)$/
ABresult
0X0
100
111
687  
688 5 our %scriptstylemap = (display => 'script', text => 'script',
689 script => 'scriptscript', scriptscript => 'scriptscript');
690 5 our %fracstylemap = (display => 'text', text => 'script',
691 script => 'scriptscript', scriptscript => 'scriptscript');
692 5 our %stylesize = (display => 10, text => 10,
693 script => 7, scriptscript => 5);
694  
695 # NOTE: In math, NORMALLY, setting any one of
696 # family, series or shape
697 # will, usually, automatically reset the others to thier defaults!
698 # You must arrange this in the calls....
699 0 ▶sub merge {
Subroutine merge: not called CC=36 SCAR=71.9
Pod undocumented
700 0 my ($self, %options) = @_;
701 # Evaluate any functional values given.
702 0 foreach my $k (keys %options) {
703 0 ▶ $options{$k} = &{ $options{$k} }() if ref $options{$k} eq 'CODE'; }
Branch: 1 branch
BranchTrueFalseTotal
if ref $options{$k} eq "CODE" 0 0 0
704  
705 0 my $family = $options{family};
706 0 my $series = $options{series};
707 0 my $shape = $options{shape};
708 0 my $size = rationalizeFontSize($options{size});
709 0 my $color = $options{color};
710 0 my $bg = $options{background};
711 0 my $opacity = $options{opacity};
712 0 my $encoding = $options{encoding};
713 0 my $language = $options{language};
714 0 my $mathstyle = $options{mathstyle};
715  
716 0 ▶ if ($options{forcebold}) { # for compatibility
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"forcebold"}) 0 0 0
717 0 $series = 'bold'; $options{forceseries} = 1; }
718 my $flags = 0
719 | ($options{forcefamily} ? $FLAG_FORCE_FAMILY : 0)
720 | ($options{forceseries} ? $FLAG_FORCE_SERIES : 0)
721 0 ▶ | ($options{forceshape} ? $FLAG_FORCE_SHAPE : 0);
Branch: 3 branches
BranchTrueFalseTotal
$options{'forcefamily'} ? : 0 0 0
$options{'forceseries'} ? : 0 0 0
$options{'forceshape'} ? : 0 0 0
722  
723 0 my $oflags = $$self[10];
724 # Fallback to positional invocation:
725 0 ▶ $family = $$self[0] if (!defined $family) || ($oflags & $FLAG_FORCE_FAMILY);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $family or $oflags & $FLAG_FORCE_FAMILY 0 0 0
Condition0%0/3
not defined $family or $oflags & $FLAG_FORCE_FAMILY
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $family or $oflags & $FLAG_FORCE_FAMILY
not defined $family $oflags & $FLAG_FORCE_FAMILY
Truth table0%0/3
not(A) or B
A= not defined $familyB= $oflags & $FLAG_FORCE_FAMILY
ABresult
1X1
011
000
726 0 ▶ $series = $$self[1] if (!defined $series) || ($oflags & $FLAG_FORCE_SERIES);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $series or $oflags & $FLAG_FORCE_SERIES 0 0 0
Condition0%0/3
not defined $series or $oflags & $FLAG_FORCE_SERIES
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $series or $oflags & $FLAG_FORCE_SERIES
not defined $series $oflags & $FLAG_FORCE_SERIES
Truth table0%0/3
not(A) or B
A= not defined $seriesB= $oflags & $FLAG_FORCE_SERIES
ABresult
1X1
011
000
727 0 ▶ $shape = $$self[2] if (!defined $shape) || ($oflags & $FLAG_FORCE_SHAPE);
Branch: 1 branch
BranchTrueFalseTotal
if not defined $shape or $oflags & $FLAG_FORCE_SHAPE 0 0 0
Condition0%0/3
not defined $shape or $oflags & $FLAG_FORCE_SHAPE
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $shape or $oflags & $FLAG_FORCE_SHAPE
not defined $shape $oflags & $FLAG_FORCE_SHAPE
Truth table0%0/3
not(A) or B
A= not defined $shapeB= $oflags & $FLAG_FORCE_SHAPE
ABresult
1X1
011
000
728 0 ▶ $size = $$self[3] if (!defined $size);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $size 0 0 0
729 0 ▶ $color = $$self[4] if (!defined $color);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $color 0 0 0
730 0 ▶ $bg = $$self[5] if (!exists $options{background});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $options{"background"} 0 0 0
731 0 ▶ $opacity = $$self[6] if (!defined $opacity);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $opacity 0 0 0
732 0 ▶ $encoding = $$self[7] if (!defined $encoding);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $encoding 0 0 0
733 0 ▶ $language = $$self[8] if (!defined $language);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $language 0 0 0
734 0 ▶ $mathstyle = $$self[9] if (!defined $mathstyle);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mathstyle 0 0 0
735 0 ▶ $flags = ($$self[10] || 0) | $flags;
Condition0%0/2
$self->[10] || 0
l!l
00
MC/DC0%0/1
$self->[10] || 0
$self->[10]
Truth table0%0/2
A
A= $self->[10]
Aresult
11
00
736  
737 0 ▶ if (my $scale = $options{scale}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $scale = $options{"scale"}) 0 0 0
738 0 $size = $scale * $size; }
739 # Set the mathstyle, and also the size from the mathstyle
740 # But we may need to scale that size against the existing or requested size.
741 0 ▶ my $stylescale = ($$self[3] ? $$self[3] / $stylesize{ $$self[9] || 'display' } : 1);
Branch: 1 branch
BranchTrueFalseTotal
$self->[3] ? : 0 0 0
Condition0%0/2
$self->[9] || 'display'
l!l
00
MC/DC0%0/1
$self->[9] || 'display'
$self->[9]
Truth table0%0/2
A
A= $self->[9]
Aresult
11
00
742 0 ▶ if ($options{size}) { } # Explicitly requested size, use it
Branch: 4 branches
BranchTrueFalseTotal
if ($options{'size'}) { } 0 0 0
elsif ($options{'mathstyle'}) { } 0 0 0
elsif ($options{'scripted'}) { } 0 0 0
elsif ($options{'fraction'}) { } 0 0 0
743 elsif ($options{mathstyle}) { # otherwise set the size from mathstyle
744 0 $size = $stylescale * $stylesize{$mathstyle}; }
745 elsif ($options{scripted}) { # Or adjust both the mathstyle & size for scripts
746 0 ▶ $mathstyle = $scriptstylemap{ $mathstyle || 'display' };
Condition0%0/2
$mathstyle || 'display'
l!l
00
MC/DC0%0/1
$mathstyle || 'display'
$mathstyle
Truth table0%0/2
A
A= $mathstyle
Aresult
11
00
747 0 ▶ $size = $stylescale * $stylesize{ $mathstyle || 'display' }; }
Condition0%0/2
$mathstyle || 'display'
l!l
00
MC/DC0%0/1
$mathstyle || 'display'
$mathstyle
Truth table0%0/2
A
A= $mathstyle
Aresult
11
00
748 elsif ($options{fraction}) { # Or adjust both for fractions
749 0 ▶ $mathstyle = $fracstylemap{ $mathstyle || 'display' };
Condition0%0/2
$mathstyle || 'display'
l!l
00
MC/DC0%0/1
$mathstyle || 'display'
$mathstyle
Truth table0%0/2
A
A= $mathstyle
Aresult
11
00
750 0 ▶ $size = $stylescale * $stylesize{ $mathstyle || 'display' }; }
Condition0%0/2
$mathstyle || 'display'
l!l
00
MC/DC0%0/1
$mathstyle || 'display'
$mathstyle
Truth table0%0/2
A
A= $mathstyle
Aresult
11
00
751  
752 0 ▶ if ($options{emph}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($options{"emph"}) 0 0 0
753 0 ▶ $shape = ($shape eq 'italic' ? 'upright' : 'italic');
Branch: 1 branch
BranchTrueFalseTotal
$shape eq 'italic' ? : 0 0 0
754 0 $flags |= $FLAG_EMPH; }
755 0 ▶ $flags &= ~$FLAG_EMPH if $mathstyle; # Disable emph in math
Branch: 1 branch
BranchTrueFalseTotal
if $mathstyle 0 0 0
756  
757 0 my $newfont = (ref $self)->new_internal($family, $series, $shape, $size,
758 $color, $bg, $opacity,
759 $encoding, $language,
760 $mathstyle, $flags);
761 0 ▶ if (my $specialize = $options{specialize}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $specialize = $options{"specialize"}) 0 0 0
762 0 $newfont = $newfont->specialize($specialize); }
763 0 return $newfont; }
764  
765 # Instanciate the font for a particular class of symbols.
766 # NOTE: This works in `normal' latex, but probably needs some tunability.
767 # Depending on the fonts being used, the allowable combinations may be different.
768 # Getting the font right is important, since the author probably
769 # thinks of the identity of the symbols according to what they SEE in the printed
770 # document. Even though the markup might seem to indicate something else...
771  
772 # Use Unicode properties to determine font merging.
773 0 ▶sub specialize {
Subroutine specialize: not called CC=30 SCAR=68.4
Pod documented
774 0 my ($self, $string) = @_;
775 0 ▶ return $self if !(defined $string) || ref $string; # ?
Branch: 1 branch
BranchTrueFalseTotal
if not defined $string or ref $string 0 0 0
Condition0%0/3
not defined $string or ref $string
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $string or ref $string
not defined $string ref $string
Truth table0%0/3
not(A) or B
A= not defined $stringB= ref $string
ABresult
1X1
011
000
776 0 my ($family, $series, $shape, $size, $color, $bg, $opacity,
777 $encoding, $language, $mathstyle, $flags) = @$self;
778 0 ▶ my $deffamily = ($flags & $FLAG_FORCE_FAMILY ? $family || $DEFFAMILY : $DEFFAMILY);
Branch: 1 branch
BranchTrueFalseTotal
$flags & $FLAG_FORCE_FAMILY ? : 0 0 0
Condition0%0/3
$family or $DEFFAMILY
l!l&&r!l&&!r
000
MC/DC0%0/2
$family or $DEFFAMILY
$family $DEFFAMILY
Truth table0%0/3
A or B
A= $familyB= $DEFFAMILY
ABresult
1X1
011
000
779 0 ▶ my $defseries = ($flags & $FLAG_FORCE_SERIES ? $series || $DEFSERIES : $DEFSERIES);
Branch: 1 branch
BranchTrueFalseTotal
$flags & $FLAG_FORCE_SERIES ? : 0 0 0
Condition0%0/3
$series or $DEFSERIES
l!l&&r!l&&!r
000
MC/DC0%0/2
$series or $DEFSERIES
$series $DEFSERIES
Truth table0%0/3
A or B
A= $seriesB= $DEFSERIES
ABresult
1X1
011
000
780 0 ▶ my $defshape = ($flags & $FLAG_FORCE_SHAPE ? $shape || $DEFSHAPE : $DEFSHAPE);
Branch: 1 branch
BranchTrueFalseTotal
$flags & $FLAG_FORCE_SHAPE ? : 0 0 0
Condition0%0/3
$shape or $DEFSHAPE
l!l&&r!l&&!r
000
MC/DC0%0/2
$shape or $DEFSHAPE
$shape $DEFSHAPE
Truth table0%0/3
A or B
A= $shapeB= $DEFSHAPE
ABresult
1X1
011
000
781 0 ▶ if (($string =~ /^\p{Latin}$/) && ($string =~ /^\p{L}$/)) { # Latin Letter
Branch: 3 branches
BranchTrueFalseTotal
if ($string =~ /^\p{Latin}$/ and $string =~ /^\p{L}$/) { } 0 0 0
elsif ($string =~ /^\p{Greek}$/) { } 0 0 0
elsif ($string =~ /^\p{N}$/) { } 0 0 0
Condition0%0/3
$string =~ /^\p{Latin}$/ and $string =~ /^\p{L}$/
!ll&&!rl&&r
000
MC/DC0%0/2
$string =~ /^\p{Latin}$/ and $string =~ /^\p{L}$/
$string =~ /^\p{Latin}$/ $string =~ /^\p{L}$/
Truth table0%0/3
A and B
A= $string =~ /^\p{Latin}$/B= $string =~ /^\p{L}$/
ABresult
0X0
100
111
782 0 ▶ $shape = 'italic' if !$shape && !$family; }
Branch: 1 branch
BranchTrueFalseTotal
unless $shape or $family 0 0 0
Condition0%0/3
$shape or $family
l!l&&r!l&&!r
000
MC/DC0%0/2
$shape or $family
$shape $family
Truth table0%0/3
A or B
A= $shapeB= $family
ABresult
1X1
011
000
783 elsif ($string =~ /^\p{Greek}$/) { # Single Greek character?
784 0 ▶ if ($string =~ /^\p{Lu}$/) { # Uppercase
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /^\p{Lu}$/) { } 0 0 0
785 0 ▶ if (!$family || ($family eq 'math')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $family or $family eq "math") 0 0 0
Condition0%0/3
not $family or $family eq "math"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $family or $family eq "math"
not $family $family eq "math"
Truth table0%0/3
not(A) or B
A= not $familyB= $family eq "math"
ABresult
1X1
011
000
786 0 $family = $deffamily;
787 0 ▶ $shape = $defshape if $shape && ($shape ne $DEFSHAPE); } } # if ANY shape, must be default
Branch: 1 branch
BranchTrueFalseTotal
if $shape and $shape ne $DEFSHAPE 0 0 0
Condition0%0/3
$shape and $shape ne $DEFSHAPE
!ll&&!rl&&r
000
MC/DC0%0/2
$shape and $shape ne $DEFSHAPE
$shape $shape ne $DEFSHAPE
Truth table0%0/3
A and B
A= $shapeB= $shape ne $DEFSHAPE
ABresult
0X0
100
111
788 else { # Lowercase
789 0 ▶ $family = $deffamily if !$family || ($family ne $DEFFAMILY);
Branch: 1 branch
BranchTrueFalseTotal
if not $family or $family ne $DEFFAMILY 0 0 0
Condition0%0/3
not $family or $family ne $DEFFAMILY
l!l&&r!l&&!r
000
MC/DC0%0/2
not $family or $family ne $DEFFAMILY
not $family $family ne $DEFFAMILY
Truth table0%0/3
not(A) or B
A= not $familyB= $family ne $DEFFAMILY
ABresult
1X1
011
000
790 0 ▶ $shape = 'italic' if !$shape || !($flags & $FLAG_FORCE_SHAPE); # always ?
Branch: 1 branch
BranchTrueFalseTotal
unless $shape and $flags & $FLAG_FORCE_SHAPE 0 0 0
Condition0%0/3
$shape and $flags & $FLAG_FORCE_SHAPE
!ll&&!rl&&r
000
MC/DC0%0/2
$shape and $flags & $FLAG_FORCE_SHAPE
$shape $flags & $FLAG_FORCE_SHAPE
Truth table0%0/3
A and B
A= $shapeB= $flags & $FLAG_FORCE_SHAPE
ABresult
0X0
100
111
791 0 ▶ if ($series && ($series ne $DEFSERIES)) { $series = $defseries; }
Branch: 1 branch
BranchTrueFalseTotal
if ($series and $series ne $DEFSERIES) 0 0 0
Condition0%0/3
$series and $series ne $DEFSERIES
!ll&&!rl&&r
000
MC/DC0%0/2
$series and $series ne $DEFSERIES
$series $series ne $DEFSERIES
Truth table0%0/3
A and B
A= $seriesB= $series ne $DEFSERIES
ABresult
0X0
100
111
792 } }
793 elsif ($string =~ /^\p{N}$/) { # Digit
794 0 ▶ if (!$family || ($family eq 'math')) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $family or $family eq "math") 0 0 0
Condition0%0/3
not $family or $family eq "math"
l!l&&r!l&&!r
000
MC/DC0%0/2
not $family or $family eq "math"
not $family $family eq "math"
Truth table0%0/3
not(A) or B
A= not $familyB= $family eq "math"
ABresult
1X1
011
000
795 0 $family = $deffamily;
796 0 $shape = $defshape; } } # defaults, always.
797 else { # Other Symbol
798 0 $family = $deffamily;
799 0 $shape = $defshape; # defaults, always.
800 0 ▶ if ($series && ($series ne $DEFSERIES)) { $series = $defseries; } }
Branch: 1 branch
BranchTrueFalseTotal
if ($series and $series ne $DEFSERIES) 0 0 0
Condition0%0/3
$series and $series ne $DEFSERIES
!ll&&!rl&&r
000
MC/DC0%0/2
$series and $series ne $DEFSERIES
$series $series ne $DEFSERIES
Truth table0%0/3
A and B
A= $seriesB= $series ne $DEFSERIES
ABresult
0X0
100
111
801 0 return (ref $self)->new_internal($family, $series, $shape, $size,
802 $color, $bg, $opacity,
803 $encoding, $language, $mathstyle, $flags); }
804  
805 # A special form of merge when copying/moving nodes to a new context,
806 # particularly math which become scripts or such.
807 5 our %mathstylestep = (
808 display => { display => 0, text => 1, script => 2, scriptscript => 3 },
809 text => { display => -1, text => 0, script => 1, scriptscript => 2 },
810 script => { display => -2, text => -1, script => 0, scriptscript => 1 },
811 scriptscript => { display => -3, text => -2, script => -1, scriptscript => 0 });
812 5 our %stepmathstyle = (
813 display => { -3 => 'display', -2 => 'display', -1 => 'display',
814 0 => 'display', 1 => 'text', 2 => 'script', 3 => 'scriptscript' },
815 text => { -3 => 'display', -2 => 'display', -1 => 'display',
816 0 => 'text', 1 => 'script', 2 => 'scriptscript', 3 => 'scriptscript' },
817 script => { -3 => 'display', -2 => 'display', -1 => 'text',
818 0 => 'script', 1 => 'scriptscript', 2 => 'scriptscript', 3 => 'scriptscript' },
819 scriptscript => { -3 => 'display', -2 => 'text', -1 => 'script',
820 0 => 'scriptscript', 1 => 'scriptscript', 2 => 'scriptscript', 3 => 'scriptscript' });
821  
822 0 ▶sub purestyleChanges {
Subroutine purestyleChanges: not called CC=4 SCAR=30.0
Pod undocumented
823 0 my ($self, $other) = @_;
824 0 my $mathstyle = $self->getMathstyle;
825 0 my $othermathstyle = $other->getMathstyle;
826 0 my $othercolor = $other->getColor;
827 return (
828 scale => $other->getSize / $self->getSize,
829 (isDiff($othercolor, $DEFCOLOR) ? (color => $othercolor) : ()),
830 background => $other->getBackground,
831 opacity => $other->getOpacity, # should multiply or replace?
832 ($mathstyle && $othermathstyle
833 0 ▶ ? (mathstylestep => $mathstylestep{$mathstyle}{$othermathstyle})
Branch: 2 branches
BranchTrueFalseTotal
isDiff($othercolor, $DEFCOLOR) ? : 0 0 0
$mathstyle && $othermathstyle ? : 0 0 0
Condition0%0/3
$mathstyle and $othermathstyle
!ll&&!rl&&r
000
MC/DC0%0/2
$mathstyle and $othermathstyle
$mathstyle $othermathstyle
Truth table0%0/3
A and B
A= $mathstyleB= $othermathstyle
ABresult
0X0
100
111
834 : ()),
835 ); }
836  
837 0 ▶sub mergePurestyle {
Subroutine mergePurestyle: not called CC=6 SCAR=37.4
Pod undocumented
838 0 my ($self, %stylechanges) = @_;
839 0 my $new = $self->new_internal(@$self);
840 0 ▶ $$new[3] = $$self[3] * $stylechanges{scale} if $stylechanges{scale};
Branch: 1 branch
BranchTrueFalseTotal
if $stylechanges{"scale"} 0 0 0
841 0 ▶ $$new[4] = $stylechanges{color} if $stylechanges{color};
Branch: 1 branch
BranchTrueFalseTotal
if $stylechanges{"color"} 0 0 0
842 0 ▶ $$new[5] = $stylechanges{background} if $stylechanges{background};
Branch: 1 branch
BranchTrueFalseTotal
if $stylechanges{"background"} 0 0 0
843 0 ▶ $$new[6] = $stylechanges{opacity} if $stylechanges{opacity};
Branch: 1 branch
BranchTrueFalseTotal
if $stylechanges{"opacity"} 0 0 0
844 0 ▶ $$new[9] = $stepmathstyle{ $$self[9] }{ $stylechanges{mathstylestep} } if $stylechanges{mathstylestep};
Branch: 1 branch
BranchTrueFalseTotal
if $stylechanges{"mathstylestep"} 0 0 0
845 0 return new; }
846  
847 #**********************************************************************
848 5 1;
849  
850 __END__
« lib/LaTeXML/Util/Pack.pm ↑ Summary lib/LaTeXML/Post/MakeBibliography.pm »