lib/LaTeXML/Post/PictureImages.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 80 CC 8 SCAR 22.3
CC
8
Cov
0%
new
20.0
find_documentclass_and_packages
12.0
extractTeX
12.0
CRAP 9.3
1 # /=====================================================================\ #
2 # | LaTeXML::Post::PictureImages | #
3 # | Postprocessor to create images for picture | #
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  
13 package LaTeXML::Post::PictureImages;
14 use strict;
15 use warnings;
16 use LaTeXML::Post;
17 use base qw(LaTeXML::Post::LaTeXImages);
18  
19 sub new {
20 my ($class, %options) = @_;
21 $options{resource_directory} = 'pic' unless defined $options{resource_directory};
22 $options{resource_prefix} = 'pic' unless defined $options{resource_prefix};
23 $options{use_dvipng} = 0 unless defined $options{use_dvipng};
24 return $class->SUPER::new(%options); }
25  
26 #======================================================================
27  
28 sub find_documentclass_and_packages {
29 my ($self, $doc) = @_;
30 my ($classdata, @packages) = $self->SUPER::find_documentclass_and_packages($doc);
31 # If we haven't already included graphics or graphicx
32 if (!grep { /graphic(:?s|x)/ } @packages) {
33 # and if a picture has @scale
34 if ($doc->findnodes('//ltx:picture[@scale]')) {
35 # Then load graphicx as well
36 push(@packages, ['graphicx', '']); } }
37 return ($classdata, @packages); }
38  
39 # Return the list of Picture nodes.
40 sub toProcess {
41 my ($self, $doc) = @_;
42 return $doc->findnodes('//ltx:picture'); }
43  
44 # Return the TeX string to format the image for this node.
45 sub extractTeX {
46 my ($self, $doc, $node) = @_;
47 my $tex = $self->cleanTeX($node->getAttribute('tex') || '');
48 $tex =~ s/\n//gs; # trim stray CR's
49 if (my $u = $node->getAttribute('unitlength')) {
50 $tex = "\\setlength{\\unitlength}{$u}" . $tex; }
51 # xunitlength, yunitlength for pstricks???
52 if (my $s = $node->getAttribute('scale')) {
53 $tex = "\\scalebox{$s}{$tex}"; }
54 return "\\beginPICTURE $tex\\endPICTURE"; }
55  
56 sub process {
57 my ($self, $doc, @nodes) = @_;
58 return $self->generateImages($doc, @nodes); }
59  
60 sub setTeXImage {
61 my ($self, $doc, $node, $path, $width, $height, $depth) = @_;
62 $self->SUPER::setTeXImage($doc, $node, $path, $width, $height, $depth);
63 # Since the width & height attributes can get exposed in the XSLT (CSS)
64 # adjust them to match the size actually computed
65 # $node->setAttribute(width => $width . "pt");
66 # $node->setAttribute(height => $height . "pt");
67 # But, since the inner image (of whatever format) will already get a size,
68 # it's probably safer to just remove those attributes?
69 $node->removeAttribute('width');
70 $node->removeAttribute('height');
71 return; }
72  
73 # Definitions needed for processing inline & display picture images
74 sub preamble {
75 my ($self, $doc) = @_;
76 return <<'EOPreamble';
77 \def\scalePicture#1{\setlength{\unitlength}{#1 \unitlength}
78 \@tempdimb\f@size\p@ \@tempdimb#1\@tempdimb
79 \fontsize{\strip@pt\@tempdimb}{\strip@pt\@tempdimb}\selectfont}
80 \def\beginPICTURE{\lxBeginImage}
81 \def\endPICTURE{\lxEndImage\lxShowImage}
82 EOPreamble
83 }
84 #======================================================================
85 1;