summaryrefslogtreecommitdiff
path: root/vcl/source/fontsubset
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2018-05-29 12:00:11 +0200
committerStephan Bergmann <sbergman@redhat.com>2018-05-29 14:21:47 +0200
commitd4992bb36efb15da91a70e86e68a80f13b97e947 (patch)
treee17ad8f8c013fef98d63473fed58eea4d5f5e830 /vcl/source/fontsubset
parent0611e0643101c9282934de872249b438bd1a7f53 (diff)
Change SFErrCodes to scoped enum
Change-Id: Ib2f267397e419e8164bb2d732f7cbcca7acad1a6 Reviewed-on: https://gerrit.libreoffice.org/54996 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'vcl/source/fontsubset')
-rw-r--r--vcl/source/fontsubset/fontsubset.cxx4
-rw-r--r--vcl/source/fontsubset/sft.cxx79
-rw-r--r--vcl/source/fontsubset/ttcr.cxx22
-rw-r--r--vcl/source/fontsubset/ttcr.hxx8
4 files changed, 57 insertions, 56 deletions
diff --git a/vcl/source/fontsubset/fontsubset.cxx b/vcl/source/fontsubset/fontsubset.cxx
index b15b0956e971..8d2e1cf14218 100644
--- a/vcl/source/fontsubset/fontsubset.cxx
+++ b/vcl/source/fontsubset/fontsubset.cxx
@@ -132,7 +132,7 @@ bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths )
// remove const_cast when sft-subsetter is const-correct
sal_uInt8* pEncArray = const_cast<sal_uInt8*>( mpReqEncodedIds );
#endif
- int nSFTErr = vcl::SF_BADARG;
+ vcl::SFErrCodes nSFTErr = vcl::SFErrCodes::BadArg;
if( mnReqFontTypeMask & FontType::TYPE42_FONT )
{
nSFTErr = CreateT42FromTTGlyphs( mpSftTTFont, mpOutFile, mpReqFontName,
@@ -150,7 +150,7 @@ bool FontSubsetInfo::CreateFontSubsetFromSfnt( sal_Int32* pOutGlyphWidths )
// TODO: move functionality from callers here
}
- return (nSFTErr != vcl::SF_OK);
+ return (nSFTErr != vcl::SFErrCodes::Ok);
}
// TODO: replace dummy implementation
diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx
index bcb1ba251132..dfe167b9f901 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -1375,36 +1375,37 @@ static void allocTrueTypeFont( TrueTypeFont** ttf )
}
/* forward declaration for the two entry points to use*/
-static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t );
+static SFErrCodes doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t );
#if !defined(_WIN32)
-int OpenTTFontFile( const char* fname, sal_uInt32 facenum, TrueTypeFont** ttf )
+SFErrCodes OpenTTFontFile( const char* fname, sal_uInt32 facenum, TrueTypeFont** ttf )
{
- int ret, fd = -1;
+ SFErrCodes ret;
+ int fd = -1;
struct stat st;
- if (!fname || !*fname) return SF_BADFILE;
+ if (!fname || !*fname) return SFErrCodes::BadFile;
allocTrueTypeFont( ttf );
if( ! *ttf )
- return SF_MEMORY;
+ return SFErrCodes::Memory;
(*ttf)->fname = strdup(fname);
if( ! (*ttf)->fname )
{
- ret = SF_MEMORY;
+ ret = SFErrCodes::Memory;
goto cleanup;
}
fd = open(fname, O_RDONLY);
if (fd == -1) {
- ret = SF_BADFILE;
+ ret = SFErrCodes::BadFile;
goto cleanup;
}
if (fstat(fd, &st) == -1) {
- ret = SF_FILEIO;
+ ret = SFErrCodes::FileIo;
goto cleanup;
}
@@ -1415,12 +1416,12 @@ int OpenTTFontFile( const char* fname, sal_uInt32 facenum, TrueTypeFont** ttf )
* Size will be 0, but fonts smaller than 4 bytes would be broken anyway.
*/
if ((*ttf)->fsize == 0) {
- ret = SF_BADFILE;
+ ret = SFErrCodes::BadFile;
goto cleanup;
}
if (((*ttf)->ptr = static_cast<sal_uInt8 *>(mmap(nullptr, (*ttf)->fsize, PROT_READ, MAP_SHARED, fd, 0))) == MAP_FAILED) {
- ret = SF_MEMORY;
+ ret = SFErrCodes::Memory;
goto cleanup;
}
close(fd);
@@ -1437,11 +1438,11 @@ cleanup:
}
#endif
-int OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf)
+SFErrCodes OpenTTFontBuffer(const void* pBuffer, sal_uInt32 nLen, sal_uInt32 facenum, TrueTypeFont** ttf)
{
allocTrueTypeFont( ttf );
if( *ttf == nullptr )
- return SF_MEMORY;
+ return SFErrCodes::Memory;
(*ttf)->fname = nullptr;
(*ttf)->fsize = nLen;
@@ -1480,12 +1481,12 @@ public:
}
-static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
+static SFErrCodes doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
{
TTFontCloser aCloseGuard(t);
if (t->fsize < 4) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
int i;
sal_uInt32 length, tag;
@@ -1499,18 +1500,18 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
tdoffset = 0;
} else if (TTCTag == T_ttcf) { /* TrueType collection */
if (!withinBounds(12, 4 * facenum, sizeof(sal_uInt32), t->fsize)) {
- return SF_FONTNO;
+ return SFErrCodes::FontNo;
}
sal_uInt32 Version = GetUInt32(t->ptr, 4);
if (Version != 0x00010000 && Version != 0x00020000) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
if (facenum >= GetUInt32(t->ptr, 8)) {
- return SF_FONTNO;
+ return SFErrCodes::FontNo;
}
tdoffset = GetUInt32(t->ptr, 12 + 4 * facenum);
} else {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
if (withinBounds(tdoffset, 0, 4 + sizeof(sal_uInt16), t->fsize)) {
@@ -1518,7 +1519,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
}
if (t->ntables >= 128 || t->ntables == 0) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
t->tables = static_cast<const sal_uInt8**>(calloc(NUM_TAGS, sizeof(sal_uInt8 *)));
@@ -1568,7 +1569,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
if( facenum == sal_uInt32(~0) ) {
sal_uInt8* pHead = const_cast<sal_uInt8*>(t->tables[O_head]);
if (!pHead) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
/* limit Head candidate to TTC extract's limits */
if( pHead > t->ptr + (t->fsize - 54) )
@@ -1586,7 +1587,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
}
}
if (p <= t->ptr) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
}
@@ -1627,7 +1628,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
*/
if( !(getTable(t, O_maxp) && getTable(t, O_head) && getTable(t, O_name) && getTable(t, O_cmap)) ) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
const sal_uInt8* table = getTable(t, O_maxp);
@@ -1637,13 +1638,13 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
table = getTable(t, O_head);
table_size = getTableSize(t, O_head);
if (table_size < 52) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
t->unitsPerEm = GetUInt16(table, 18);
int indexfmt = GetInt16(table, 50);
if( ((indexfmt != 0) && (indexfmt != 1)) || (t->unitsPerEm <= 0) ) {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
if( getTable(t, O_glyf) && getTable(t, O_loca) ) /* TTF or TTF-OpenType */
@@ -1666,7 +1667,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
/* TODO: implement to get subsetting */
assert(t->goffsets != nullptr);
} else {
- return SF_TTFORMAT;
+ return SFErrCodes::TtFormat;
}
table = getTable(t, O_hhea);
@@ -1682,7 +1683,7 @@ static int doOpenTTFont( sal_uInt32 facenum, TrueTypeFont* t )
aCloseGuard.clear();
- return SF_OK;
+ return SFErrCodes::Ok;
}
void CloseTTFont(TrueTypeFont *ttf)
@@ -1755,7 +1756,7 @@ int GetTTGlyphComponents(TrueTypeFont *ttf, sal_uInt32 glyphID, std::vector< sal
return n;
}
-int CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname,
+SFErrCodes CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname,
sal_uInt16 const *glyphArray, sal_uInt8 *encoding, int nGlyphs,
int wmode)
{
@@ -1813,8 +1814,8 @@ int CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname,
const char * const h41 = "(%s) cvn exch definefont pop\n";
- if (!((nGlyphs > 0) && (nGlyphs <= 256))) return SF_GLYPHNUM;
- if (!glyphArray) return SF_BADARG;
+ if (!((nGlyphs > 0) && (nGlyphs <= 256))) return SFErrCodes::GlyphNum;
+ if (!glyphArray) return SFErrCodes::BadArg;
if (!fname) fname = ttf->psname;
fprintf(outf, h01, GetInt16(table, 0), GetUInt16(table, 2), GetInt16(table, 4), GetUInt16(table, 6));
@@ -1904,10 +1905,10 @@ int CreateT3FromTTGlyphs(TrueTypeFont *ttf, FILE *outf, const char *fname,
fprintf(outf, "%s", h40);
fprintf(outf, h41, fname);
- return SF_OK;
+ return SFErrCodes::Ok;
}
-int CreateTTFromTTGlyphs(TrueTypeFont *ttf,
+SFErrCodes CreateTTFromTTGlyphs(TrueTypeFont *ttf,
const char *fname,
sal_uInt16 const *glyphArray,
sal_uInt8 const *encoding,
@@ -1916,7 +1917,7 @@ int CreateTTFromTTGlyphs(TrueTypeFont *ttf,
TrueTypeCreator *ttcr;
TrueTypeTable *head=nullptr, *hhea=nullptr, *maxp=nullptr, *cvt=nullptr, *prep=nullptr, *glyf=nullptr, *fpgm=nullptr, *cmap=nullptr, *name=nullptr, *post = nullptr, *os2 = nullptr;
int i;
- int res;
+ SFErrCodes res;
TrueTypeCreatorNewEmpty(T_true, &ttcr);
@@ -1997,9 +1998,9 @@ int CreateTTFromTTGlyphs(TrueTypeFont *ttf,
AddTable(ttcr, cvt ); AddTable(ttcr, prep); AddTable(ttcr, fpgm);
AddTable(ttcr, post); AddTable(ttcr, os2);
- if ((res = StreamToFile(ttcr, fname)) != SF_OK) {
+ if ((res = StreamToFile(ttcr, fname)) != SFErrCodes::Ok) {
#if OSL_DEBUG_LEVEL > 1
- fprintf(stderr, "StreamToFile: error code: %d.\n", res);
+ fprintf(stderr, "StreamToFile: error code: %d.\n", int(res));
#endif
}
@@ -2155,7 +2156,7 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen)
free(offs);
}
-int CreateT42FromTTGlyphs(TrueTypeFont *ttf,
+SFErrCodes CreateT42FromTTGlyphs(TrueTypeFont *ttf,
FILE *outf,
const char *psname,
sal_uInt16 const *glyphArray,
@@ -2165,7 +2166,7 @@ int CreateT42FromTTGlyphs(TrueTypeFont *ttf,
TrueTypeCreator *ttcr;
TrueTypeTable *head=nullptr, *hhea=nullptr, *maxp=nullptr, *cvt=nullptr, *prep=nullptr, *glyf=nullptr, *fpgm=nullptr;
int i;
- int res;
+ SFErrCodes res;
sal_uInt32 ver, rev;
@@ -2173,7 +2174,7 @@ int CreateT42FromTTGlyphs(TrueTypeFont *ttf,
sal_uInt32 sfntLen;
int UPEm = ttf->unitsPerEm;
- if (nGlyphs >= 256) return SF_GLYPHNUM;
+ if (nGlyphs >= 256) return SFErrCodes::GlyphNum;
assert(psname != nullptr);
@@ -2224,7 +2225,7 @@ int CreateT42FromTTGlyphs(TrueTypeFont *ttf,
AddTable(ttcr, head); AddTable(ttcr, hhea); AddTable(ttcr, maxp); AddTable(ttcr, cvt);
AddTable(ttcr, prep); AddTable(ttcr, glyf); AddTable(ttcr, fpgm);
- if ((res = StreamToMemory(ttcr, &sfntP, &sfntLen)) != SF_OK) {
+ if ((res = StreamToMemory(ttcr, &sfntP, &sfntLen)) != SFErrCodes::Ok) {
TrueTypeCreatorDispose(ttcr);
free(gID);
return res;
@@ -2264,7 +2265,7 @@ int CreateT42FromTTGlyphs(TrueTypeFont *ttf,
TrueTypeCreatorDispose(ttcr);
free(gID);
free(sfntP);
- return SF_OK;
+ return SFErrCodes::Ok;
}
#if defined(_WIN32) || defined(MACOSX) || defined(IOS)
diff --git a/vcl/source/fontsubset/ttcr.cxx b/vcl/source/fontsubset/ttcr.cxx
index fd6703e5a0b7..0a6ca74b20db 100644
--- a/vcl/source/fontsubset/ttcr.cxx
+++ b/vcl/source/fontsubset/ttcr.cxx
@@ -161,12 +161,12 @@ void TrueTypeCreatorNewEmpty(sal_uInt32 tag, TrueTypeCreator **_this)
*_this = ptr;
}
-int AddTable(TrueTypeCreator *_this, TrueTypeTable *table)
+SFErrCodes AddTable(TrueTypeCreator *_this, TrueTypeTable *table)
{
if (table != nullptr) {
listAppend(_this->tables, table);
}
- return SF_OK;
+ return SFErrCodes::Ok;
}
void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag)
@@ -193,14 +193,14 @@ void RemoveTable(TrueTypeCreator *_this, sal_uInt32 tag)
static void ProcessTables(TrueTypeCreator *);
-int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length)
+SFErrCodes StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length)
{
sal_uInt16 searchRange=1, entrySelector=0, rangeShift;
sal_uInt32 s, offset, checkSumAdjustment = 0;
sal_uInt32 *p;
sal_uInt8 *head = nullptr; /* saved pointer to the head table data for checkSumAdjustment calculation */
- if (listIsEmpty(_this->tables)) return SF_TTFORMAT;
+ if (listIsEmpty(_this->tables)) return SFErrCodes::TtFormat;
ProcessTables(_this);
@@ -269,29 +269,29 @@ int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length)
*ptr = ttf;
*length = s;
- return SF_OK;
+ return SFErrCodes::Ok;
}
-int StreamToFile(TrueTypeCreator *_this, const char* fname)
+SFErrCodes StreamToFile(TrueTypeCreator *_this, const char* fname)
{
sal_uInt8 *ptr;
sal_uInt32 length;
- int r;
+ SFErrCodes r;
FILE* fd;
- if ((r = StreamToMemory(_this, &ptr, &length)) != SF_OK) return r;
+ if ((r = StreamToMemory(_this, &ptr, &length)) != SFErrCodes::Ok) return r;
if (fname && (fd = fopen(fname, "wb")) != nullptr)
{
if (fwrite(ptr, 1, length, fd) != length) {
- r = SF_FILEIO;
+ r = SFErrCodes::FileIo;
} else {
- r = SF_OK;
+ r = SFErrCodes::Ok;
}
fclose(fd);
}
else
{
- r = SF_BADFILE;
+ r = SFErrCodes::BadFile;
}
free(ptr);
return r;
diff --git a/vcl/source/fontsubset/ttcr.hxx b/vcl/source/fontsubset/ttcr.hxx
index a5a28e612652..5acd5230ecd8 100644
--- a/vcl/source/fontsubset/ttcr.hxx
+++ b/vcl/source/fontsubset/ttcr.hxx
@@ -64,10 +64,10 @@ namespace vcl
/**
* Adds a TrueType table to the TrueType creator.
- * SF_TABLEFORMAT value.
+ * SFErrCodes::TableFormat value.
* @return value of SFErrCodes type
*/
- int AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
+ SFErrCodes AddTable(TrueTypeCreator *_this, TrueTypeTable *table);
/**
* Removes a TrueType table from the TrueType creator if it is stored there.
@@ -84,13 +84,13 @@ namespace vcl
* is supposed to call free() on it.
* @return value of SFErrCodes type
*/
- int StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length);
+ SFErrCodes StreamToMemory(TrueTypeCreator *_this, sal_uInt8 **ptr, sal_uInt32 *length);
/**
* Writes a TrueType font generated by the TrueTypeCreator to a file
* @return value of SFErrCodes type
*/
- int StreamToFile(TrueTypeCreator *_this, const char* fname);
+ SFErrCodes StreamToFile(TrueTypeCreator *_this, const char* fname);
/**
* This function converts the data of a TrueType table to a raw array of bytes.