NCBI C++ ToolKit
pdf_font_handler.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: pdf_font_handler.cpp 44822 2020-03-23 16:10:20Z evgeniev $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software / database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software / database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Peter Meric
27  *
28  * File Description:
29  * CPdfFontHandler - handle PDF fonts
30  */
31 
32 
33 #include <ncbi_pch.hpp>
36 #include <gui/print/pdf_object.hpp>
37 //#include <gui/opengl/ftglfontmanager.hpp>
38 
39 
41 
42 
43 
45  : m_ObjIdGenerator(objid_generator)
46 {
47  Init();
48 }
49 
50 
52 {
53 }
54 
55 
57 {
59  if (it == m_FontNames.end()) {
60  NCBI_THROW(CException, eUnknown, "CPdfFontHandler::GetFontName: font face "
61  + NStr::IntToString(int(fontface)) + " not loaded");
62  }
63 
64  return it->second;
65 }
66 
67 
69 {
71  CPdfObject& _f = *f;
72  const string name("F" + NStr::NumericToString(m_FontNum));
73 
74  EFontFace pdf_face;
75 
76  _f["Type"] = new CPdfName("Font");
77  _f["Subtype"] = new CPdfName("Type1");
78  //_f["Subtype"] = new CPdfName("TrueType");
79  _f["Name"] = new CPdfName(name);
80  _f["BaseFont"] = new CPdfName(CGlTextureFont::PdfBaseFontName(fontface, pdf_face));
81 
82  m_FontNames[fontface] = name;
83  m_Fonts.push_back(f);
84 
85  ++m_FontNum;
86 }
87 
88 
90 {
91  vector<string> faces;
93  EFontFace pdf_face;
94 
95  // Add all fonts that can be specified as type-1 (built-in) fonts
96  for (size_t i=0; i<faces.size(); ++i) {
98  if ( CGlTextureFont::PdfBaseFontName(f, pdf_face) != "" )
100  }
101 }
102 
103 
105 {
106  return m_Fonts;
107 }
108 
109 
CIdGenerator - generates consecutive integer identifiers.
CRef< CIdGenerator > m_ObjIdGenerator
string GetFontName(EFontFace fontface) const
void x_AddFont(EFontFace fontface)
virtual ~CPdfFontHandler()
const TObjectList & GetFontObjects(void) const
CPdfFontHandler(CIdGenerator *objid_generator)
list< TPdfObjectRef > TObjectList
map< EFontFace, string > m_FontNames
const_iterator end() const
Definition: map.hpp:152
const_iterator find(const key_type &key) const
Definition: map.hpp:153
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
Definition: ncbiexpt.hpp:704
static void GetAllFaces(vector< string > &faces)
GetAllFaces() and GetAllSizes() fills containers with strings repesenting all available enumerated (p...
static string PdfBaseFontName(EFontFace face, EFontFace &pdf_face)
Name of basefont for PDF purposes, or "" if not available.
EFontFace
Set of pre-defined fonts for which we know we have valid font files.
static EFontFace FaceFromString(const string &str)
Selects a font face given a string or eFontFace_LastFont on failure.
unsigned int NextId(void)
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static string IntToString(int value, TNumToStringFlags flags=0, int base=10)
Convert int to string.
Definition: ncbistr.hpp:5084
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
Definition: ncbistr.hpp:673
int i
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Modified on Wed Jun 19 17:06:19 2024 by modify_doxy.py rev. 669887