Skip to content

Commit

Permalink
Color tweaks (#2236)
Browse files Browse the repository at this point in the history
* Don't set internal pgf colors if not in pgf

* Make default color Black (the object) rather than the string 'black'

* Make default color Black (the object) rather than the string 'black'

* Use a more sensible test for Black color

* Make Black (the object) default color, rather than string 'black'

* Update tests so that black comes out as '#000000'
  • Loading branch information
brucemiller authored Oct 15, 2023
1 parent 56886ab commit 1ad2590
Show file tree
Hide file tree
Showing 18 changed files with 693 additions and 691 deletions.
7 changes: 4 additions & 3 deletions lib/LaTeXML/Common/Font.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use LaTeXML::Common::Number;
use LaTeXML::Common::Dimension;
use LaTeXML::Common::Font::Metric;
use LaTeXML::Common::Font::StandardMetrics;
use LaTeXML::Common::Color;
use List::Util qw(min max sum);
use base qw(LaTeXML::Common::Object);
use base qw(LaTeXML::Common::Object);

# Note that this has evolved way beynond just "font",
# but covers text properties (or even display properties) in general
Expand All @@ -34,7 +35,7 @@ DebuggableFeature('size-detailed', "Show sizing of boxes in detail");
my $DEFFAMILY = 'serif'; # [CONSTANT]
my $DEFSERIES = 'medium'; # [CONSTANT]
my $DEFSHAPE = 'upright'; # [CONSTANT]
my $DEFCOLOR = 'black'; # [CONSTANT]
my $DEFCOLOR = Black; # [CONSTANT]
my $DEFBACKGROUND = undef; # [CONSTANT] no color; transparent
my $DEFOPACITY = '1'; # [CONSTANT]
my $DEFENCODING = 'OT1'; # [CONSTANT]
Expand Down Expand Up @@ -871,7 +872,7 @@ The attributes are
size : TINY, Tiny, tiny, SMALL, Small, small,
normal, Normal, large, Large, LARGE,
huge, Huge, HUGE, gigantic, Gigantic, GIGANTIC
color : any named color, default is black
color : any named color, default is Black
They are usually merged against the current font, attempting to mimic the,
sometimes counter-intuitive, way that TeX does it, particularly for math
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package.pm
Original file line number Diff line number Diff line change
Expand Up @@ -4647,7 +4647,7 @@ Likely values include (the values aren't required to be in this set):
shape : upright, italic, slanted, smallcaps
size : tiny, footnote, small, normal, large,
Large, LARGE, huge, Huge
color : any named color, default is black
color : any color, default is Black
Some families will only be used in math.
This function returns nothing so it can be easily used in beforeDigest, afterDigest.
Expand Down
15 changes: 8 additions & 7 deletions lib/LaTeXML/Package/LaTeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -4994,10 +4994,11 @@ sub picScale {

sub picProperties {
my (%props) = @_;
if (($props{stroke} || 'black') ne 'none') {
if (($props{stroke} || '') ne 'none') {
$props{thick} = ptValue(LookupRegister('\@wholewidth')); }
if (my $arrowlength = LookupValue('arrowlength')) {
$props{arrowlength} = ptValue($arrowlength); }
$props{color} = Black unless defined $props{color};
return %props; }

#----------------------------------------------------------------------
Expand Down Expand Up @@ -5061,11 +5062,11 @@ DefConstructor('\lx@pic@put Pair{}',
mode => 'text');

DefConstructor('\line Pair:Number {Float}',
"<ltx:line points='#points' stroke='black' stroke-width='#thick'/>",
"<ltx:line points='#points' stroke='#color' stroke-width='#thick'/>",
alias => '\line',
properties => sub { picProperties(points => '0,0 ' . slopeToPicCoord($_[1], $_[2])->pxValue()); });
DefConstructor('\vector Pair:Number {Float}',
"<ltx:line points='#points' stroke='black' stroke-width='#thick' terminators='->'"
"<ltx:line points='#points' stroke='#color' stroke-width='#thick' terminators='->'"
. " arrowlength='#arrowlength'/>",
alias => '\vector',
properties => sub { picProperties(points => '0,0 ' . slopeToPicCoord($_[1], $_[2])->pxValue()); });
Expand All @@ -5075,11 +5076,11 @@ DefConstructor('\circle OptionalMatch:* {Float}',
properties => sub {
my ($stomach, $filled, $dia) = @_;
picProperties(radius => picScale($dia)->multiply(0.5)->pxValue,
($filled ? 'fill' : 'stroke') => 'black'); });
($filled ? 'fill' : 'stroke') => Black); });

DefConstructor('\oval [Float] Pair []',
"<ltx:rect x='#x' y='#y' width='#width' height='#height' rx='#radius'"
. " stroke='black' fill='none' part='#3' stroke-width='#thick'/>",
. " stroke='#color' fill='none' part='#3' stroke-width='#thick'/>",
alias => '\oval',
properties => sub {
my ($stomach, $r, $size, $part) = @_;
Expand All @@ -5095,7 +5096,7 @@ DefConstructor('\oval [Float] Pair []',
); });

DefConstructor('\qbezier [Number] Pair Pair Pair',
"<ltx:bezier ?#1(displayedpoints='#1') points='&ptValue(#pt)' stroke='black' stroke-width='#thick' />",
"<ltx:bezier ?#1(displayedpoints='#1') points='&ptValue(#pt)' stroke='#color' stroke-width='#thick' />",
alias => '\qbezier',
properties => sub {
picProperties(pt => PairList(picScale($_[2]), picScale($_[3]), picScale($_[4]))); });
Expand All @@ -5110,7 +5111,7 @@ DefConstructor('\lx@pic@bezier {Number} Pair Pair Pair',
# Generic boxing command (frames, dash, etc)
DefConstructor('\pic@makebox@ Undigested RequiredKeyVals Pair []{}',
"?#framed(<ltx:rect x='0' y='0' width='#fwidth' height='#fheight'"
. " stroke='black' stroke-width='#thick' fill='none' stroke-dasharray='#dash'/>)()"
. " stroke='#color' stroke-width='#thick' fill='none' stroke-dasharray='#dash'/>)()"
. "<ltx:g class='makebox' innerwidth='#width' innerheight='#height' innerdepth='#depth'"
. " transform='translate(#xshift,#yshift)'>#box</ltx:g>",
reversion => '#1#3[#4]{#5}',
Expand Down
6 changes: 3 additions & 3 deletions lib/LaTeXML/Package/TeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ sub adjustBoxColor {
my ($box) = @_;
my $font = LookupValue('font');
if (my $color = $font && $font->getColor) {
if ($color ne 'black') {
if (!Black->equals($color)) {
adjustBoxColor_rec($color, {}, $box); } }
return; }

Expand Down Expand Up @@ -2402,7 +2402,7 @@ DefConstructor('\vrule RuleSpecification',
elsif ((defined $w) && ($w == 0)) {
$whatsit->setProperty(invisible => 1); }
if (my $color = LookupValue('font')->getColor) {
if ($color ne 'black') {
if (!Black->equals($color)) {
$whatsit->setProperty(color => $color); } }
return; });

Expand Down Expand Up @@ -2432,7 +2432,7 @@ DefConstructor('\hrule RuleSpecification',
$alignment->addLine('t');
$whatsit->setProperty(isHorizontalRule => 1) } } # Marked as rule within alignment
if (my $color = LookupValue('font')->getColor) {
if ($color ne 'black') {
if (!Black->equals($color)) {
$whatsit->setProperty(color => $color); } }
return; });

Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/diagbox.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ DefConstructor('\lx@diagbox RequiredKeyVals:diagbox {}[]{}',
M => $M, Mx => $Mx, My => $My, Mw => $Bw, Mh => $Mh,
line1 => $line1, line2 => $line2,
linewidth => ($kv && $kv->getValue('linewidth')) || '0.4',
linecolor => ($kv && $kv->getValue('linecolor')) || 'black'); }
linecolor => ($kv && $kv->getValue('linecolor')) || Black); }
);

# slashbox compatibility
Expand Down
8 changes: 4 additions & 4 deletions lib/LaTeXML/Package/makecell.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ DefMacro('\lx@diag@head{}{}',

DefConstructor('\lx@diagheads {}{} {}{}{}',
"<ltx:picture width='&pxValue(#width)' height='&pxValue(#height)'>"
. "<ltx:line points='#line' stroke='black' stroke-width='0.4'/>"
. "<ltx:line points='#line' stroke='#color' stroke-width='0.4'/>"
. "<ltx:g transform='translate(#Ax,#Ay)' innerwidth='#Aw' innerheight='#Ah' innerdepth='#Ad'>"
. "<ltx:inline-block>#A</ltx:inline-block>"
. "</ltx:g>"
Expand Down Expand Up @@ -84,9 +84,9 @@ DefConstructor('\lx@diagheads {}{} {}{}{}',
my $pxppt = Dimension('1pt')->pxValue(10);
$whatsit->setProperties(
width => Dimension($w / $pxppt . 'pt'), height => Dimension($h / $pxppt . 'pt'),
A => $A, Ax => $Ax, Ay => $Ay, Aw => $Aw, Ah => $Ah,
B => $B, Bx => $Bx, By => $By, Bw => $Bw, Bh => $Bh,
line => $line); }
A => $A, Ax => $Ax, Ay => $Ay, Aw => $Aw, Ah => $Ah,
B => $B, Bx => $Bx, By => $By, Bw => $Bw, Bh => $Bh,
line => $line, color => Black); }
);
#======================================================================
1;
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/pgfsys-latexml.def.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ AtBeginDocument('\def\XC@mcolor{\pgfsetcolor{.}}');
# Implementation

DefMacro('\pgfsys@color@rgb{}{}{}',
'\pgfsys@color@rgb@stroke{#1}{#2}{#3}\pgfsys@color@rgb@fill{#1}{#2}{#3}');
'\ifpgfpicture\pgfsys@color@rgb@stroke{#1}{#2}{#3}\pgfsys@color@rgb@fill{#1}{#2}{#3}\fi');

DefMacro('\lxSVG@RGB{}{}{}', sub { Explode(Color('rgb', $_[1], $_[2], $_[3])->toHex); });
DefMacro('\lxSVG@CMYK{}{}{}{}', sub { Explode(Color('cmyk', $_[1], $_[2], $_[3], $_[4])->toHex); });
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Package/wasysym.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use LaTeXML::Package;

#======================================================================

DefPrimitiveI('\ataribox', undef, "\x{26CB}", font => { color => 'white', background => 'black' }, bounded => 1);
DefPrimitiveI('\ataribox', undef, "\x{26CB}", font => { color => White, background => Black }, bounded => 1);
DefMathI('\Join', undef, "\x{2a1d}");
DefMathI('\Box', undef, "\x{25a1}");
DefMathI('\Diamond', undef, "\x{25c7}");
Expand Down
2 changes: 1 addition & 1 deletion t/alignment/cells.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
<thead>
<tr>
<td align="left" border="l r t" class="ltx_nopad" thead="column row"><picture height="41.34" tex="\diaghead(4,1){\hskip 119.50148pt}{{\color[rgb]{1,0,0}\shortstack[r]{Diag \\&#10;Column Head I}}}{{\color[rgb]{1,0,0}\shortstack[l]{Diag Column \\&#10;Head II}}}" width="165.35" xml:id="S10.p1.pic1">
<line points="0,0, 165.35,41.3375" stroke="black" stroke-width="0.4"/>
<line points="0,0, 165.35,41.3375" stroke="#000000" stroke-width="0.4"/>
<g innerheight="25.91" innerwidth="93.02" transform="translate(72.33,0)">
<inline-block>
<inline-block align="right">
Expand Down
44 changes: 22 additions & 22 deletions t/alignment/diagboxtest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<tr>
<td align="left" border="r t" thead="column row">NW</td>
<td align="center" border="r t" class="ltx_nopad" thead="column"><picture height="18.92" tex="\diagbox[dir={NW}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{}" width="20.76" xml:id="p1.pic1">
<line points="0,18.92 20.76,0" stroke="black" stroke-width="0.4"/>
<line points="0,18.92 20.76,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand All @@ -34,7 +34,7 @@
<tr>
<td align="left" border="r t" thead="row">SE</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="18.92" tex="\diagbox[dir={SE}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{}" width="20.76" xml:id="p1.pic2">
<line points="0,18.92 20.76,0" stroke="black" stroke-width="0.4"/>
<line points="0,18.92 20.76,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand All @@ -54,7 +54,7 @@
<tr>
<td align="left" border="r t" thead="row">SW</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="18.92" tex="\diagbox[dir={SW}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{}" width="20.76" xml:id="p1.pic3">
<line points="0,0, 20.76,18.92" stroke="black" stroke-width="0.4"/>
<line points="0,0, 20.76,18.92" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,9.46)">
<inline-block>
<inline-block align="left">
Expand All @@ -74,7 +74,7 @@
<tr>
<td align="left" border="b r t" thead="row">NE</td>
<td align="center" border="b r t" class="ltx_nopad"><picture height="18.92" tex="\diagbox[dir={NE}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{}" width="20.76" xml:id="p1.pic4">
<line points="0,0, 20.76,18.92" stroke="black" stroke-width="0.4"/>
<line points="0,0, 20.76,18.92" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,9.46)">
<inline-block>
<inline-block align="left">
Expand All @@ -100,8 +100,8 @@
<tr>
<td align="left" border="r t" thead="column row">NW</td>
<td align="center" border="r t" class="ltx_nopad" thead="column"><picture height="24.27" tex="\diagbox[dir={NW}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{{\shortstack[l]{M%&#10;}}}" width="28.74" xml:id="p2.pic1">
<line points="14.37,24.27 28.74,0" stroke="black" stroke-width="0.4"/>
<line points="0,12.135 28.74,0" stroke="black" stroke-width="0.4"/>
<line points="14.37,24.27 28.74,0" stroke="#000000" stroke-width="0.4"/>
<line points="0,12.135 28.74,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -130,8 +130,8 @@
<tr>
<td align="left" border="r t" thead="row">SE</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="24.27" tex="\diagbox[dir={SE}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{{\shortstack[r]{M%&#10;}}}" width="28.74" xml:id="p2.pic2">
<line points="0,24.27 28.74,12.135" stroke="black" stroke-width="0.4"/>
<line points="0,24.27 14.37,0" stroke="black" stroke-width="0.4"/>
<line points="0,24.27 28.74,12.135" stroke="#000000" stroke-width="0.4"/>
<line points="0,24.27 14.37,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand All @@ -158,8 +158,8 @@
<tr>
<td align="left" border="r t" thead="row">SW</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="24.27" tex="\diagbox[dir={SW}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{{\shortstack[l]{M%&#10;}}}" width="28.74" xml:id="p2.pic3">
<line points="0,12.135 28.74,24.27" stroke="black" stroke-width="0.4"/>
<line points="14.37,0 28.74,24.27" stroke="black" stroke-width="0.4"/>
<line points="0,12.135 28.74,24.27" stroke="#000000" stroke-width="0.4"/>
<line points="14.37,0 28.74,24.27" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,14.81)">
<inline-block>
<inline-block align="left">
Expand All @@ -186,8 +186,8 @@
<tr>
<td align="left" border="b r t" thead="row">NE</td>
<td align="center" border="b r t" class="ltx_nopad"><picture height="24.27" tex="\diagbox[dir={NE}]{{\shortstack[l]{A}}}{{\shortstack[r]{B}}}{{\shortstack[r]{M%&#10;}}}" width="28.74" xml:id="p2.pic4">
<line points="0,0 14.37,24.27" stroke="black" stroke-width="0.4"/>
<line points="0,0 28.74,12.135" stroke="black" stroke-width="0.4"/>
<line points="0,0 14.37,24.27" stroke="#000000" stroke-width="0.4"/>
<line points="0,0 28.74,12.135" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="9.46" innerwidth="10.38" transform="translate(0,14.81)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -220,8 +220,8 @@
<tr>
<td align="left" border="r t" thead="column row">NW</td>
<td align="center" border="r t" class="ltx_nopad" thead="column"><picture height="60.79" tex="\diagbox[dir={NW}]{{\shortstack[l]{Word\\&#10;A}}}{{\shortstack[r]{Word\\&#10;B}}}{{\shortstack[l]{Word\\&#10;M}}}" width="86.63" xml:id="p3.pic1">
<line points="43.315,60.79 86.63,0" stroke="black" stroke-width="0.4"/>
<line points="0,30.395 86.63,0" stroke="black" stroke-width="0.4"/>
<line points="43.315,60.79 86.63,0" stroke="#000000" stroke-width="0.4"/>
<line points="0,30.395 86.63,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="23.22" innerwidth="33.09" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -253,8 +253,8 @@
<tr>
<td align="left" border="r t" thead="row">SE</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="60.79" tex="\diagbox[dir={SE}]{{\shortstack[l]{Word\\&#10;A}}}{{\shortstack[r]{Word\\&#10;B}}}{{\shortstack[r]{Word\\&#10;M}}}" width="86.63" xml:id="p3.pic2">
<line points="0,60.79 86.63,30.395" stroke="black" stroke-width="0.4"/>
<line points="0,60.79 43.315,0" stroke="black" stroke-width="0.4"/>
<line points="0,60.79 86.63,30.395" stroke="#000000" stroke-width="0.4"/>
<line points="0,60.79 43.315,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="23.22" innerwidth="33.09" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -284,8 +284,8 @@
<tr>
<td align="left" border="r t" thead="row">SW</td>
<td align="center" border="r t" class="ltx_nopad"><picture height="60.79" tex="\diagbox[dir={SW}]{{\shortstack[l]{Word\\&#10;A}}}{{\shortstack[r]{Word\\&#10;B}}}{{\shortstack[l]{Word\\&#10;M}}}" width="86.63" xml:id="p3.pic3">
<line points="0,30.395 86.63,60.79" stroke="black" stroke-width="0.4"/>
<line points="43.315,0 86.63,60.79" stroke="black" stroke-width="0.4"/>
<line points="0,30.395 86.63,60.79" stroke="#000000" stroke-width="0.4"/>
<line points="43.315,0 86.63,60.79" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="23.22" innerwidth="33.09" transform="translate(0,37.57)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -315,8 +315,8 @@
<tr>
<td align="left" border="b r t" thead="row">NE</td>
<td align="center" border="b r t" class="ltx_nopad"><picture height="60.79" tex="\diagbox[dir={NE}]{{\shortstack[l]{Word\\&#10;A}}}{{\shortstack[r]{Word\\&#10;B}}}{{\shortstack[r]{Word\\&#10;M}}}" width="86.63" xml:id="p3.pic4">
<line points="0,0 43.315,60.79" stroke="black" stroke-width="0.4"/>
<line points="0,0 86.63,30.395" stroke="black" stroke-width="0.4"/>
<line points="0,0 43.315,60.79" stroke="#000000" stroke-width="0.4"/>
<line points="0,0 86.63,30.395" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="23.22" innerwidth="33.09" transform="translate(0,37.57)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -354,7 +354,7 @@
<thead>
<tr>
<td align="center" border="l r t" class="ltx_nopad" thead="column row"><picture height="18.26" tex="\diagbox[dir={SW},width=56.9055pt]{{\shortstack[l]{num}}}{{\shortstack[r]{%&#10;alpha}}}{}" width="78.74" xml:id="p5.pic1">
<line points="0,0, 78.74,18.26" stroke="black" stroke-width="0.4"/>
<line points="0,0, 78.74,18.26" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="5.96" innerwidth="26.52" transform="translate(0,12.3)">
<inline-block>
<inline-block align="left">
Expand Down Expand Up @@ -393,7 +393,7 @@
<thead>
<tr>
<td align="center" border="l r t" class="ltx_nopad" thead="column row"><picture height="18.26" tex="\diagbox[dir={NW},width=56.9055pt]{{\shortstack[l]{num}}}{{\shortstack[r]{%&#10;alpha}}}{}" width="78.74" xml:id="p6.pic1">
<line points="0,18.26 78.74,0" stroke="black" stroke-width="0.4"/>
<line points="0,18.26 78.74,0" stroke="#000000" stroke-width="0.4"/>
<g class="ltx_svg_fog" innerheight="5.96" innerwidth="26.52" transform="translate(0,0)">
<inline-block>
<inline-block align="left">
Expand Down
Loading

0 comments on commit 1ad2590

Please sign in to comment.