Author: jghali
Date: Wed Feb 10 22:41:36 2021
New Revision: 24466

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24466
Log:
Add utility functions to retrieve glyph CIDs from glyph indexes 

Modified:
    trunk/Scribus/scribus/fonts/ftface.cpp
    trunk/Scribus/scribus/fonts/ftface.h
    trunk/Scribus/scribus/fonts/scface.cpp
    trunk/Scribus/scribus/fonts/scface.h

Modified: trunk/Scribus/scribus/fonts/ftface.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24466&path=/trunk/Scribus/scribus/fonts/ftface.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/ftface.cpp      (original)
+++ trunk/Scribus/scribus/fonts/ftface.cpp      Wed Feb 10 22:41:36 2021
@@ -198,6 +198,16 @@
        return gl;
 }
 
+ScFace::cid_type FtFace::glyphIndexToCID(ScFace::gid_type index) const
+{
+       FT_Face face = ftFace();
+
+       ScFace::cid_type cid = 0;
+       FT_Error err = FT_Get_CID_From_Glyph_Index(face, index, &cid);
+       if (err)
+               cid = index;
+       return cid;
+}
 
 void FtFace::loadGlyph(ScFace::gid_type gl) const
 {

Modified: trunk/Scribus/scribus/fonts/ftface.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24466&path=/trunk/Scribus/scribus/fonts/ftface.h
==============================================================================
--- trunk/Scribus/scribus/fonts/ftface.h        (original)
+++ trunk/Scribus/scribus/fonts/ftface.h        Wed Feb 10 22:41:36 2021
@@ -82,6 +82,7 @@
 //FIXME        QMap<QString,QString> fontDictionary(qreal sz=1.0) const;
 
        ScFace::gid_type char2CMap(uint ch) const override;
+       ScFace::cid_type glyphIndexToCID(ScFace::gid_type index) const override;
 
 //     GlyphMetrics glyphBBox (gid_type gl, qreal sz) const;
 

Modified: trunk/Scribus/scribus/fonts/scface.cpp
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24466&path=/trunk/Scribus/scribus/fonts/scface.cpp
==============================================================================
--- trunk/Scribus/scribus/fonts/scface.cpp      (original)
+++ trunk/Scribus/scribus/fonts/scface.cpp      Wed Feb 10 22:41:36 2021
@@ -26,7 +26,6 @@
        hb_font_destroy(reinterpret_cast<hb_font_t*>(m_hbFont));
        m_hbFont = nullptr;
 }
-
 
 static hb_blob_t* referenceTable(hb_face_t*, hb_tag_t tag, void *userData)
 {
@@ -94,12 +93,10 @@
        return false; 
 }
 
-
 QMap<QString,QString> ScFace::ScFaceData::fontDictionary(qreal /*sz*/) const
 {
        return QMap<QString, QString>();
 }
-
 
 GlyphMetrics ScFace::ScFaceData::glyphBBox(gid_type gl, qreal sz) const
 {
@@ -120,7 +117,6 @@
        return res;
 }
 
-
 qreal ScFace::ScFaceData::glyphWidth(gid_type gl, qreal size) const
 {
        if (gl >= CONTROL_GLYPHS)
@@ -129,7 +125,6 @@
                loadGlyph(gl);
        return m_glyphWidth[gl] * size;
 }
-
 
 FPointArray ScFace::ScFaceData::glyphOutline(gid_type gl, qreal size) const
 { 
@@ -143,7 +138,6 @@
        return res;
 }
 
-
 FPoint ScFace::ScFaceData::glyphOrigin(gid_type gl, qreal size) const
 {
        if (gl >= CONTROL_GLYPHS)
@@ -153,7 +147,6 @@
        const struct GlyphData & res(m_glyphOutline[gl]);
        return FPoint(res.x, res.y) * size;
 }
-
 
 /*****
    ScFace lifecycle:  unchecked -> loaded -> glyphs checked
@@ -179,7 +172,6 @@
        m_m->usage = 0;
 }
 
-
 ScFace::ScFace(ScFaceData* data) : m_m(data)
 {
        ++(m_m->refs);
@@ -200,7 +192,6 @@
                m_m = nullptr;
        }
 }
-
 
 ScFace& ScFace::operator=(const ScFace& other)
 {
@@ -219,7 +210,6 @@
        return *this;
 }
 
-
 /** two ScFaces are equal if they either are both NULLFACEs or they
 agree on family, style, variant and fontpath
 */
@@ -235,7 +225,6 @@
                                 && m_m-> faceIndex == other.m_m->faceIndex) );
 }
 
-
 const ScFace& ScFace::none() 
 { 
        static ScFace NONE;
@@ -381,14 +370,12 @@
        m_m->usage++;
 }
 
-
 void ScFace::decreaseUsage() const
 {
        if (m_m->usage == 1) 
                unload();
        m_m->usage--;
 }
-
 
 void ScFace::unload() const
 {
@@ -418,6 +405,7 @@
                return hyphenGlyph();
        return 0;
 }
+
 ScFace::gid_type ScFace::hyphenGlyph() const
 {
        // Try the typographic hyphen first, then the hyphen-minus
@@ -463,6 +451,14 @@
        return gl;
 }
 
+ScFace::cid_type ScFace::glyphIndexToCID(gid_type index) const
+{
+       if (m_m->status == ScFace::UNKNOWN)
+               m_m->load();
+
+       cid_type cid = m_m->glyphIndexToCID(index);
+       return cid;
+}
 
 bool ScFace::canRender(QChar ch) const 
 {
@@ -486,14 +482,12 @@
        return m_m->embedFont(str);
 }
 
-
 bool ScFace::glyphNames(FaceEncoding& gList)
 {
        if (m_m->status == ScFace::UNKNOWN)
                m_m->load();
        return m_m->glyphNames(gList);
 }
-
 
 void ScFace::rawData(QByteArray & bb)
 {

Modified: trunk/Scribus/scribus/fonts/scface.h
URL: 
http://scribus.net/websvn/diff.php?repname=Scribus&rev=24466&path=/trunk/Scribus/scribus/fonts/scface.h
==============================================================================
--- trunk/Scribus/scribus/fonts/scface.h        (original)
+++ trunk/Scribus/scribus/fonts/scface.h        Wed Feb 10 22:41:36 2021
@@ -84,6 +84,7 @@
                // handled by freetype: PFB_MAC, DFONT, HQX, MACBIN,
                SFNT, TTCF, UNKNOWN_FORMAT };
 
+       typedef uint cid_type;
        typedef uint gid_type;
        typedef uint ucs4_type;
        struct GlyphEncoding
@@ -194,6 +195,7 @@
                virtual qreal strokeWidth(qreal /*sz*/)      const { return 
0.1; }
                virtual qreal maxAdvanceWidth(qreal sz)  const { return sz; }
                virtual gid_type char2CMap(uint /*ch*/)         const { return 
0; }
+               virtual cid_type glyphIndexToCID(ScFace::gid_type index) const 
{ return index; }
                virtual QMap<QString,QString> fontDictionary(qreal sz=1.0) 
const;
                virtual GlyphMetrics glyphBBox(gid_type gl, qreal sz) const;
                virtual bool embedFont(QByteArray &/*str*/)       const { 
return false; }
@@ -396,6 +398,9 @@
        /// test if the face can render this char
        bool canRender(QChar ch)   const;
 
+       // translate glyph index to CID (OpenType and CID fonts only)
+       cid_type glyphIndexToCID(gid_type index) const;
+
        /// translate unicode to glyph index
        gid_type char2CMap(uint ch)   const;
 


_______________________________________________
scribus-commit mailing list
[email protected]
http://lists.scribus.net/mailman/listinfo/scribus-commit

Reply via email to