Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-10 10:23:45

0001 //========================================================================
0002 //
0003 // CMap.h
0004 //
0005 // Copyright 2001-2003 Glyph & Cog, LLC
0006 //
0007 //========================================================================
0008 
0009 //========================================================================
0010 //
0011 // Modified under the Poppler project - http://poppler.freedesktop.org
0012 //
0013 // All changes made under the Poppler project to this file are licensed
0014 // under GPL version 2 or later
0015 //
0016 // Copyright (C) 2008 Koji Otani <sho@bbr.jp>
0017 // Copyright (C) 2009, 2018-2020, 2022 Albert Astals Cid <aacid@kde.org>
0018 // Copyright (C) 2012, 2017 Adrian Johnson <ajohnson@redneon.com>
0019 // Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
0020 //
0021 // To see a description of the changes please see the Changelog file that
0022 // came with your tarball or type make ChangeLog if you are building from git
0023 //
0024 //========================================================================
0025 
0026 #ifndef CMAP_H
0027 #define CMAP_H
0028 
0029 #include <array>
0030 #include <atomic>
0031 #include <memory>
0032 
0033 #include "poppler-config.h"
0034 #include "CharTypes.h"
0035 
0036 class GooString;
0037 class Object;
0038 struct CMapVectorEntry;
0039 class CMapCache;
0040 class Stream;
0041 
0042 //------------------------------------------------------------------------
0043 
0044 class CMap
0045 {
0046 public:
0047     // Parse a CMap from <obj>, which can be a name or a stream.  Sets
0048     // the initial reference count to 1.  Returns NULL on failure.
0049     static std::shared_ptr<CMap> parse(CMapCache *cache, const GooString *collectionA, Object *obj);
0050 
0051     // Create the CMap specified by <collection> and <cMapName>.  Sets
0052     // the initial reference count to 1.  Returns NULL on failure.
0053     static std::shared_ptr<CMap> parse(CMapCache *cache, const GooString *collectionA, const GooString *cMapNameA);
0054 
0055     // Parse a CMap from <str>.  Sets the initial reference count to 1.
0056     // Returns NULL on failure.
0057     static std::shared_ptr<CMap> parse(CMapCache *cache, const GooString *collectionA, Stream *str);
0058 
0059     ~CMap();
0060 
0061     CMap(const CMap &) = delete;
0062     CMap &operator=(const CMap &) = delete;
0063 
0064     // Return collection name (<registry>-<ordering>).
0065     const GooString *getCollection() const { return collection; }
0066 
0067     const GooString *getCMapName() const { return cMapName; }
0068 
0069     // Return true if this CMap matches the specified <collectionA>, and
0070     // <cMapNameA>.
0071     bool match(const GooString *collectionA, const GooString *cMapNameA);
0072 
0073     // Return the CID corresponding to the character code starting at
0074     // <s>, which contains <len> bytes.  Sets *<c> to the char code, and
0075     // *<nUsed> to the number of bytes used by the char code.
0076     CID getCID(const char *s, int len, CharCode *c, int *nUsed);
0077 
0078     // Return the writing mode (0=horizontal, 1=vertical).
0079     int getWMode() const { return wMode; }
0080 
0081     void setReverseMap(unsigned int *rmap, unsigned int rmapSize, unsigned int ncand);
0082 
0083 private:
0084     void parse2(CMapCache *cache, int (*getCharFunc)(void *), void *data);
0085     CMap(GooString *collectionA, GooString *cMapNameA);
0086     CMap(GooString *collectionA, GooString *cMapNameA, int wModeA);
0087     void useCMap(CMapCache *cache, const char *useName);
0088     void useCMap(CMapCache *cache, Object *obj);
0089     void copyVector(CMapVectorEntry *dest, CMapVectorEntry *src);
0090     void addCIDs(unsigned int start, unsigned int end, unsigned int nBytes, CID firstCID);
0091     void freeCMapVector(CMapVectorEntry *vec);
0092     void setReverseMapVector(unsigned int startCode, CMapVectorEntry *vec, unsigned int *rmap, unsigned int rmapSize, unsigned int ncand);
0093 
0094     GooString *collection;
0095     GooString *cMapName;
0096     bool isIdent; // true if this CMap is an identity mapping,
0097                   //   or is based on one (via usecmap)
0098     int wMode; // writing mode (0=horizontal, 1=vertical)
0099     CMapVectorEntry *vector; // vector for first byte (NULL for
0100                              //   identity CMap)
0101 };
0102 
0103 //------------------------------------------------------------------------
0104 
0105 #define cMapCacheSize 4
0106 
0107 class CMapCache
0108 {
0109 public:
0110     CMapCache();
0111     ~CMapCache() = default;
0112 
0113     CMapCache(const CMapCache &) = delete;
0114     CMapCache &operator=(const CMapCache &) = delete;
0115 
0116     // Get the <cMapName> CMap for the specified character collection.
0117     // Increments its reference count; there will be one reference for
0118     // the cache plus one for the caller of this function.
0119     // Stream is a stream containing the CMap, can be NULL and
0120     // this means the CMap will be searched in the CMap files
0121     // Returns NULL on failure.
0122     std::shared_ptr<CMap> getCMap(const GooString *collection, const GooString *cMapName);
0123 
0124 private:
0125     std::array<std::shared_ptr<CMap>, cMapCacheSize> cache;
0126 };
0127 
0128 #endif