Coverage Report

Created: 2026-11-10 07:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/poppler/splash/SplashFTFontFile.cc
Line
Count
Source
1
//========================================================================
2
//
3
// SplashFTFontFile.cc
4
//
5
//========================================================================
6
7
//========================================================================
8
//
9
// Modified under the Poppler project - http://poppler.freedesktop.org
10
//
11
// All changes made under the Poppler project to this file are licensed
12
// under GPL version 2 or later
13
//
14
// Copyright (C) 2006 Takashi Iwai <tiwai@suse.de>
15
// Copyright (C) 2014, 2017, 2022 Adrian Johnson <ajohnson@redneon.com>
16
// Copyright (C) 2017, 2018, 2022 Oliver Sander <oliver.sander@tu-dresden.de>
17
// Copyright (C) 2018, 2024-2026 Albert Astals Cid <aacid@kde.org>
18
// Copyright (C) 2024-2026 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk>
19
//
20
// To see a description of the changes please see the Changelog file that
21
// came with your tarball or type make ChangeLog if you are building from git
22
//
23
//========================================================================
24
25
#include <config.h>
26
27
#include "goo/ft_utils.h"
28
#include "poppler/GfxFont.h"
29
#include "SplashFTFontEngine.h"
30
#include "SplashFTFont.h"
31
#include "SplashFTFontFile.h"
32
#include "SplashFontFileID.h"
33
34
//------------------------------------------------------------------------
35
// SplashFTFontFile
36
//------------------------------------------------------------------------
37
38
std::shared_ptr<SplashFontFile> SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, const std::array<const char *, 256> &encA, int faceIndexA)
39
49.9k
{
40
49.9k
    FT_Face faceA;
41
49.9k
    const char *name;
42
49.9k
    int i;
43
44
49.9k
    if (src->isFile()) {
45
0
        if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) {
46
0
            return nullptr;
47
0
        }
48
49.9k
    } else {
49
49.9k
        if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) {
50
25.9k
            return nullptr;
51
25.9k
        }
52
49.9k
    }
53
23.9k
    std::vector<int> codeToGIDA;
54
23.9k
    codeToGIDA.resize(256, 0);
55
6.16M
    for (i = 0; i < 256; ++i) {
56
6.14M
        if ((name = encA[i])) {
57
3.78M
            codeToGIDA[i] = static_cast<int>(FT_Get_Name_Index(faceA, const_cast<char *>(name)));
58
3.78M
            if (codeToGIDA[i] == 0) {
59
2.82M
                name = GfxFont::getAlternateName(name);
60
2.82M
                if (name) {
61
29.2k
                    codeToGIDA[i] = FT_Get_Name_Index(faceA, const_cast<char *>(name));
62
29.2k
                }
63
2.82M
            }
64
3.78M
        }
65
6.14M
    }
66
67
23.9k
    return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, true);
68
49.9k
}
69
70
std::shared_ptr<SplashFontFile> SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, std::vector<int> &&codeToGIDA, int faceIndexA)
71
2.41k
{
72
2.41k
    FT_Face faceA;
73
74
2.41k
    if (src->isFile()) {
75
0
        if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) {
76
0
            return nullptr;
77
0
        }
78
2.41k
    } else {
79
2.41k
        if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) {
80
715
            return nullptr;
81
715
        }
82
2.41k
    }
83
84
1.69k
    return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), false, false);
85
2.41k
}
86
87
std::shared_ptr<SplashFontFile> SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> src, std::vector<int> &&codeToGIDA, int faceIndexA)
88
104k
{
89
104k
    FT_Face faceA;
90
91
104k
    if (src->isFile()) {
92
71.8k
        if (ft_new_face_from_file(engineA->lib, src->fileName().c_str(), faceIndexA, &faceA)) {
93
0
            return nullptr;
94
0
        }
95
71.8k
    } else {
96
32.2k
        if (FT_New_Memory_Face(engineA->lib, static_cast<const FT_Byte *>(src->buf().data()), src->buf().size(), faceIndexA, &faceA)) {
97
14.2k
            return nullptr;
98
14.2k
        }
99
32.2k
    }
100
101
89.8k
    return std::make_shared<SplashFTFontFile>(engineA, std::move(idA), std::move(src), faceA, std::move(codeToGIDA), true, false);
102
104k
}
103
104
SplashFTFontFile::SplashFTFontFile(SplashFTFontEngine *engineA, std::unique_ptr<SplashFontFileID> idA, std::unique_ptr<SplashFontSrc> srcA, FT_Face faceA, std::vector<int> &&codeToGIDA, bool trueTypeA, bool type1A, PrivateTag /*unused*/)
105
115k
    : SplashFontFile(std::move(idA), std::move(srcA))
106
115k
{
107
115k
    engine = engineA;
108
115k
    face = faceA;
109
115k
    codeToGID = std::move(codeToGIDA);
110
115k
    trueType = trueTypeA;
111
115k
    type1 = type1A;
112
115k
}
113
114
SplashFTFontFile::~SplashFTFontFile()
115
115k
{
116
115k
    if (face) {
117
115k
        FT_Done_Face(face);
118
115k
    }
119
115k
}
120
121
SplashFont *SplashFTFontFile::makeFont(const std::array<double, 4> &mat, const std::array<double, 4> &textMat)
122
209k
{
123
209k
    SplashFont *font;
124
125
209k
    font = new SplashFTFont(this->shared_from_this(), mat, textMat);
126
209k
    font->initCache();
127
209k
    return font;
128
209k
}