Skip to content

Commit

Permalink
(Mostly) sort through and separate "CID" font concept
Browse files Browse the repository at this point in the history
into distinct concepts (has a ROS, has an FDSelect).
Eliminate Adobe.Identity ROS from CFF2
  • Loading branch information
skef committed May 31, 2024
1 parent 75429ba commit d5fbac1
Show file tree
Hide file tree
Showing 35 changed files with 247 additions and 258 deletions.
6 changes: 3 additions & 3 deletions c/addfeatures/cb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ void cbConvert(cbCtx h, int flags, const char *clientVers, const char *infile,
char outpath[FILENAME_MAX + 1];
int freeFeatName = 0;
unsigned long hotConvertFlags = 0;
bool isCID;
bool isROS;

if (otherflags & OTHERFLAGS_DO_ID2_GSUB_CHAIN_CONXT) {
hotConvertFlags |= HOT_ID2_CHAIN_CONTXT3;
Expand Down Expand Up @@ -727,7 +727,7 @@ void cbConvert(cbCtx h, int flags, const char *clientVers, const char *infile,

/* Read in font file */
sFileOpen(&h->in.file, inpath, "rb");
FontName = hotReadFont(h->hot.ctx, flags, isCID);
FontName = hotReadFont(h->hot.ctx, flags, isROS);

if (uvsFile != NULL) {
hotAddUVSMap(h->hot.ctx, uvsFile);
Expand All @@ -736,7 +736,7 @@ void cbConvert(cbCtx h, int flags, const char *clientVers, const char *infile,
/* Determine dir that feature file's in */
h->feat.mainFile = featurefile;

if (isCID) {
if (isROS) {
if (hcmapfile == NULL) {
cbFatal(h, "no CMaps specified [%s]\n", inpath);
}
Expand Down
8 changes: 4 additions & 4 deletions c/addfeatures/hotconv/FeatCtx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ GID FeatCtx::mapGName2GID(const char *gname, bool allowNotdef) {
GID gid;
const char *realname;

// if (IS_CID(g)) {
// if (IS_ROS(g)) {
// zzerr("glyph name specified for a CID font");
// }
if ( gname[0] == '\\' )
Expand All @@ -258,7 +258,7 @@ GID FeatCtx::mapGName2GID(const char *gname, bool allowNotdef) {

GID FeatCtx::cid2gid(const std::string &cidstr) {
GID gid = 0; /* Suppress optimizer warning */
if (!IS_CID(g)) {
if (!IS_ROS(g)) {
featMsg(sERROR, "CID specified for a non-CID font");
} else {
int t = strtoll(cidstr.c_str() + 1, NULL, 10); /* Skip initial '\' */
Expand Down Expand Up @@ -416,7 +416,7 @@ void FeatCtx::addRangeToCurrentGC(GID first, GID last, const std::string &firstN
const std::string &lastName) {
#define INVALID_RANGE featMsg(sFATAL, "Invalid glyph range [%s-%s]", \
firstName.c_str(), lastName.c_str())
if (IS_CID(g)) {
if (IS_ROS(g)) {
if (first <= last) {
for (GID i = first; i <= last; i++) {
addGlyphToCurrentGC(i);
Expand Down Expand Up @@ -514,7 +514,7 @@ bool FeatCtx::compareGlyphClassCount(int targc, int replc, bool isSubrule) {
void FeatCtx::dumpGlyph(GID gid, int ch, bool print) {
char msg[512];
int len;
if (IS_CID(g)) {
if (IS_ROS(g)) {
len = snprintf(msg, sizeof(msg), "\\%hd", mapGID2CID(gid));
} else {
mapGID2Name(g, gid, msg, sizeof(msg));
Expand Down
4 changes: 2 additions & 2 deletions c/addfeatures/hotconv/cmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ void cmapBeginEncoding(hotCtx g, unsigned platformId, unsigned scriptId,
h->mapping.cnt = 0;
h->codespace.cnt = 0;

if (h->platformId == cmap_MAC && !IS_CID(g)) {
if (h->platformId == cmap_MAC && !IS_ROS(g)) {
addMacControlChars(g, h);
}
}
Expand Down Expand Up @@ -1104,7 +1104,7 @@ int cmapEndEncoding(hotCtx g) {
if (h->platformId == cmap_MAC) {
/* Mac cmap is required; the space wasn't present, so: */
cmapAddMapping(g, 0, GID_NOTDEF, 1);
} else if (!((IS_CID(g)) && (h->platformId == cmap_MS) && (h->scriptId == cmap_MS_UGL))) {
} else if (!((IS_ROS(g)) && (h->platformId == cmap_MS) && (h->scriptId == cmap_MS_UGL))) {
/* Ms cmap is required; the space wasn't present, so: */
return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions c/addfeatures/hotconv/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ struct FontInfo_ { /* Font information */
unsigned short flags;
#define FI_MISC_FLAGS_MASK 0x01ff /* Flags from client via hotAddMiscData()*/
#define FI_FIXED_PITCH (1 << 13) /* Fixed pitch font */
#define FI_CID (1 << 15) /* CID font */
#define FI_ROS (1 << 15) /* ROS font */
std::string FontName;
std::string Notice;
std::string FamilyName;
Expand Down Expand Up @@ -321,7 +321,7 @@ struct FontInfo_ { /* Font information */
dnaDCL(short, values); /* [nPairs] */
} kern;
dnaDCL(CharName, unenc); /* Unencoded chars */
struct { /* --- CID-specific data */
struct { /* --- ROS-specific data */
std::string registry;
std::string ordering;
unsigned short supplement;
Expand All @@ -332,7 +332,7 @@ struct FontInfo_ { /* Font information */
/* The Mac pollutes my namespace with FontInfo already, hence the underscore */

/* Convenience macros */
#define IS_CID(g) ((g)->font.flags & FI_CID)
#define IS_ROS(g) ((g)->font.flags & FI_ROS)

/* -------------------------------- Contexts ------------------------------- */
typedef struct mapCtx_ *mapCtx;
Expand Down
21 changes: 12 additions & 9 deletions c/addfeatures/hotconv/glyphmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

#include "glyphmetrics.h"

#include <limits>
#include <algorithm>

#include "common.h"

std::vector<Fixed> &GlyphMetrics::getLocationScalars(uint32_t location) {
Expand Down Expand Up @@ -64,20 +67,20 @@ void GlyphMetrics::beginGlyph(abfGlyphInfo *info) {
getLocationScalars(0);
if (hctxptr != nullptr) {
auto &glyph = hctxptr->glyphs[currentGID];

if (info->gname.ptr != NULL)
glyph.gname = info->gname.ptr;
if (IS_CID(hctxptr))
if (IS_ROS(hctxptr))
glyph.id = info->cid;
else
glyph.id = info->gname.impl; // The SID (when CFF 1)

glyph.code = info->encoding.code;
abfEncoding *e = info->encoding.next;
while (e != NULL) {
while (e != NULL) {
glyph.sup.push_back(e->code);
e = e->next;
}
}
}
}
for (auto l : neededLocations) {
Expand Down Expand Up @@ -249,14 +252,14 @@ void GlyphMetrics::finishInstanceState(uint16_t gid, size_t i) {
if (im.left < hctxptr->font.minBearing.left)
hctxptr->font.minBearing.left = im.left;

auto hAdv = hctxptr->glyphs[gid].hAdv;
auto hAdv = hctxptr->glyphs[gid].hAdv;
if (hAdv - im.right < hctxptr->font.minBearing.right)
hctxptr->font.minBearing.right = hAdv - im.right;

if (im.right > hctxptr->font.maxExtent.h)
hctxptr->font.maxExtent.h = im.right;
}
}
}
}

void GlyphMetrics::initialProcessingRun(hotCtx g) {
neededLocations.clear();
Expand Down
9 changes: 5 additions & 4 deletions c/addfeatures/hotconv/glyphmetrics.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved. This software is licensed as OpenSource, under the Apache License, Version 2.0. This license is available at: http://opensource.org/licenses/Apache-2.0. */
/* Copyright 2024 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved.
This software is licensed as OpenSource, under the Apache License, Version 2.0. This license is available at: http://opensource.org/licenses/Apache-2.0. */

#ifndef ADDFEATURES_HOTCONV_VARMETRICS_H_
#define ADDFEATURES_HOTCONV_VARMETRICS_H_
#ifndef ADDFEATURES_HOTCONV_GLYPHMETRICS_H_
#define ADDFEATURES_HOTCONV_GLYPHMETRICS_H_

#include <cassert>
#include <memory>
Expand Down Expand Up @@ -95,4 +96,4 @@ class GlyphMetrics {
itemVariationStore scratchIvs;
};

#endif // ADDFEATURES_HOTCONV_VARMETRICS_H_
#endif // ADDFEATURES_HOTCONV_GLYPHMETRICS_H_
18 changes: 8 additions & 10 deletions c/addfeatures/hotconv/hot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ static void hotReadTables(hotCtx g) {
}

/* Convert PostScript font to CFF and read result */
const char *hotReadFont(hotCtx g, int flags, bool &isCID) {
const char *hotReadFont(hotCtx g, int flags, bool &isROS) {
abfTopDict *top;

hotReadTables(g);
Expand All @@ -366,7 +366,7 @@ const char *hotReadFont(hotCtx g, int flags, bool &isCID) {
g->ctx.gm = new GlyphMetrics(g->ctx.cfr, *g->ctx.locMap, g->logger);

/* Create and copy font strings */
if ((top->sup.flags & ABF_CID_FONT) && top->cid.CIDFontName.ptr) {
if ((top->sup.flags & ABF_ROS_FONT) && top->cid.CIDFontName.ptr) {
g->font.FontName = top->cid.CIDFontName.ptr;
} else if (top->FDArray.cnt > 0 && top->FDArray.array[0].FontName.ptr) {
// XXX what about CID?
Expand Down Expand Up @@ -402,16 +402,14 @@ const char *hotReadFont(hotCtx g, int flags, bool &isCID) {
g->font.UnderlinePosition = top->UnderlinePosition;
g->font.UnderlineThickness = top->UnderlineThickness;

if (top->sup.flags & ABF_CID_FONT) {
if (top->sup.flags & ABF_ROS_FONT) {
/* Copy CIDFont data */
if (top->cid.Registry.ptr)
g->font.cid.registry = top->cid.Registry.ptr;
if (top->cid.Ordering.ptr)
g->font.cid.ordering = top->cid.Ordering.ptr;
g->font.cid.supplement = top->cid.Supplement;
if (!(g->font.cid.registry == "Adobe" &&
g->font.cid.ordering == "Identity"))
g->font.flags |= FI_CID;
g->font.flags |= FI_ROS;
}

g->font.unitsPerEm = top->sup.UnitsPerEm;
Expand All @@ -435,7 +433,7 @@ const char *hotReadFont(hotCtx g, int flags, bool &isCID) {

setVendId(g);

isCID = IS_CID(g);
isROS = IS_ROS(g);

return g->font.FontName.c_str();
}
Expand Down Expand Up @@ -490,7 +488,7 @@ void hotAddVertAdvanceY(hotCtx g, GID gid, VarValueRecord &vvr) {

/* Check if encoded on platform; else use WinANSI */
static UV pfmChar2UV(hotCtx g, int code) {
hotGlyphInfo *gi = (IS_CID(g)) ? NULL : mapPlatEnc2Glyph(g, code);
hotGlyphInfo *gi = (IS_ROS(g)) ? NULL : mapPlatEnc2Glyph(g, code);

if (gi != NULL && gi->uv != UV_UNDEF) {
return gi->uv;
Expand Down Expand Up @@ -612,7 +610,7 @@ static void prepWinData(hotCtx g) {
}

/* Set typo ascender/descender/linegap */
if (IS_CID(g)) {
if (IS_ROS(g)) {
if (!font->TypoAscender.isInitialized() || !font->TypoDescender.isInitialized()) {
gid = mapUV2GID(g, UV_VERT_BOUNDS);
if (gid != GID_UNDEF)
Expand Down Expand Up @@ -665,7 +663,7 @@ static void prepWinData(hotCtx g) {
}

if (!font->TypoLineGap.isInitialized()) {
font->TypoLineGap.addValue(IS_CID(g)
font->TypoLineGap.addValue(IS_ROS(g)
? font->TypoAscender.getDefault() - font->TypoDescender.getDefault()
: EM_SCALE(1200) - font->TypoAscender.getDefault() + font->TypoDescender.getDefault());
}
Expand Down
Loading

0 comments on commit d5fbac1

Please sign in to comment.