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