1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24package installer::windows::font;
25
26use installer::files;
27use installer::globals;
28use installer::windows::idtglobal;
29
30
31#################################################################################
32# Creating the file Font.idt dynamically
33# Content:
34# File_ FontTitle
35#################################################################################
36
37sub create_font_table
38{
39	my ($filesref, $basedir) = @_;
40
41	my @fonttable = ();
42
43	installer::windows::idtglobal::write_idt_header(\@fonttable, "font");
44
45	for ( my $i = 0; $i <= $#{$filesref}; $i++ )
46	{
47		my $onefile = ${$filesref}[$i];
48		my $styles = "";
49
50		if ( $onefile->{'Styles'} ) { $styles = $onefile->{'Styles'}; }
51
52		if ( $styles =~ /\bFONT\b/ )
53		{
54			my %font = ();
55
56			$font{'File_'} = $onefile->{'uniquename'};
57			# $font{'FontTitle'} = $onefile->{'FontName'};	# results in a warning during validation
58			$font{'FontTitle'} = "";
59
60			my $oneline = $font{'File_'} . "\t" . $font{'FontTitle'} . "\n";
61
62			push(@fonttable, $oneline);
63		}
64	}
65
66	# Saving the file
67
68	my $fonttablename = $basedir . $installer::globals::separator . "Font.idt";
69	installer::files::save_file($fonttablename ,\@fonttable);
70	my $infoline = "Created idt file: $fonttablename\n";
71	$installer::logger::Lang->print($infoline);
72
73}
74
75#################################################################################
76# Reading the Font version from the ttf file, to avoid installation
77# of older files over newer files.
78#################################################################################
79
80sub get_font_version
81{
82	my ( $fontfile ) = @_;
83
84	if ( ! -f $fontfile ) { installer::exiter::exit_program("ERROR: Font file does not exist: \"$fontfile\"", "get_font_version"); }
85
86	my $fontversion = 0;
87	my $infoline = "";
88
89	my $onefile = installer::files::read_binary_file($fontfile);
90
91	if ( $onefile =~ /Version\s+(\d+\.\d+\.*\d*)/ )
92	{
93		$fontversion = $1;
94		$infoline = "FONT: Font \"$fontfile\" version: $fontversion\n";
95		$installer::logger::Lang->print($infoline);
96	}
97	else
98	{
99		$infoline = "FONT: Could not determine font version: \"$fontfile\"\n";
100		$installer::logger::Lang->print($infoline);
101	}
102
103	return $fontversion;
104}
105
1061;
107