use
vars
qw(@ISA %fields)
;
@ISA
=
qw(Font::TTF::Table)
;
sub
init
{
my
(
$k
,
$v
,
$c
);
while
(<Font::TTF::Head::DATA>)
{
(
$k
,
$v
,
$c
) = TTF_Init_Fields(
$_
,
$c
);
next
unless
defined
$k
&&
$k
ne
""
;
$fields
{
$k
} =
$v
;
}
}
sub
read
{
my
(
$self
) =
@_
;
my
(
$dat
);
$self
->SUPER::
read
||
return
$self
;
init
unless
defined
$fields
{
'Ascender'
};
$self
->{
' INFILE'
}->
read
(
$dat
, 54);
TTF_Read_Fields(
$self
,
$dat
, \
%fields
);
$self
;
}
sub
out
{
my
(
$self
,
$fh
) =
@_
;
return
$self
->SUPER::out(
$fh
)
unless
$self
->{
' read'
};
$fh
->
print
(TTF_Out_Fields(
$self
, \
%fields
, 54));
$self
;
}
sub
XML_element
{
my
(
$self
) =
shift
;
my
(
$context
,
$depth
,
$key
,
$value
) =
@_
;
my
(
$fh
) =
$context
->{
'fh'
};
my
(
$output
,
@time
);
my
(
@month
) =
qw(JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC)
;
return
$self
->SUPER::XML_element(
@_
)
unless
(
$key
eq
'created'
||
$key
eq
'modified'
);
@time
=
gmtime
(
$self
->getdate(
$key
eq
'created'
));
$output
=
sprintf
(
"%d/%s/%d %d:%d:%d"
,
$time
[3],
$month
[
$time
[4]],
$time
[5] + 1900,
$time
[2],
$time
[1],
$time
[0]);
$fh
->
print
(
"$depth<$key>$output</$key>\n"
);
$self
;
}
sub
update
{
my
(
$self
) =
@_
;
my
(
$num
,
$i
,
$loc
,
$hmtx
);
my
(
$xMin
,
$yMin
,
$xMax
,
$yMax
,
$lsbx
);
$num
=
$self
->{
' PARENT'
}{
'maxp'
}{
'numGlyphs'
};
return
undef
unless
(
defined
$self
->{
' PARENT'
}{
'hmtx'
} &&
defined
$self
->{
' PARENT'
}{
'loca'
});
$hmtx
=
$self
->{
' PARENT'
}{
'hmtx'
}->
read
;
return
undef
unless
(
$self
->{
' PARENT'
}{
'loca'
}{
' isDirty'
} ||
$hmtx
->{
' isDirty'
});
$self
->{
' PARENT'
}{
'loca'
}->update;
$hmtx
->update;
$lsbx
= 1;
for
(
$i
= 0;
$i
<
$num
;
$i
++)
{
$loc
=
$self
->{
' PARENT'
}{
'loca'
}{
'glyphs'
}[
$i
];
next
unless
defined
$loc
;
$loc
->
read
;
$xMin
=
$loc
->{
'xMin'
}
if
(
$loc
->{
'xMin'
} <
$xMin
||
$i
== 0);
$yMin
=
$loc
->{
'yMin'
}
if
(
$loc
->{
'yMin'
} <
$yMin
||
$i
== 0);
$xMax
=
$loc
->{
'xMax'
}
if
(
$loc
->{
'xMax'
} >
$xMax
);
$yMax
=
$loc
->{
'yMax'
}
if
(
$loc
->{
'yMax'
} >
$yMax
);
$lsbx
&= (
$loc
->{
'xMin'
} ==
$hmtx
->{
'lsb'
}[
$i
]);
}
$self
->{
'xMin'
} =
$xMin
;
$self
->{
'yMin'
} =
$yMin
;
$self
->{
'xMax'
} =
$xMax
;
$self
->{
'yMax'
} =
$yMax
;
if
(
$lsbx
)
{
$self
->{
'flags'
} |= 2; }
else
{
$self
->{
'flags'
} &= ~2; }
$self
->{
' isDirty'
} = 1;
$self
;
}
sub
getdate
{
my
(
$self
,
$is_create
) =
@_
;
my
(
$arr
) =
$self
->{
$is_create
?
'created'
:
'modified'
};
$arr
->[1] -= 2082844800;
if
(
$arr
->[1] < 0)
{
$arr
->[1] += 0xFFFFFFF;
$arr
->[1]++;
$arr
->[0]--;
}
return
undef
if
$arr
->[0] != 0;
return
$arr
->[1];
}
sub
setdate
{
my
(
$self
,
$time
,
$is_create
) =
@_
;
my
(
@arr
);
$arr
[1] =
$time
;
if
(
$arr
[1] >= 0x83DA4F80)
{
$arr
[1] -= 0xFFFFFFFF;
$arr
[1]--;
$arr
[0]++;
}
$arr
[1] += 2082844800;
$self
->{
$is_create
?
'created'
:
'modified'
} = \
@arr
;
$self
;
}
1;