| 1 |
/* Copyright 2014 Adobe Systems Incorporated (http://www.adobe.com/). All Rights Reserved. |
| 2 |
This software is licensed as OpenSource, under the Apache License, Version 2.0. |
| 3 |
This license is available at: http://opensource.org/licenses/Apache-2.0. */ |
| 4 |
|
| 5 |
/* |
| 6 |
* Font merging support. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include "absfont.h" |
| 10 |
|
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
static int compareOpEntries(abfOpEntry *opEntry1, abfOpEntry *opEntry2) { |
| 14 |
/* return 1 if NOT equal */ |
| 15 |
int retVal = 1; |
| 16 |
|
| 17 |
if (opEntry1->numBlends != opEntry2->numBlends) |
| 18 |
return 1; |
| 19 |
|
| 20 |
if (opEntry1->numBlends == 0) { |
| 21 |
if (opEntry1->value == opEntry2->value) |
| 22 |
return 0; |
| 23 |
else |
| 24 |
return 1; |
| 25 |
} else { |
| 26 |
int i = 0; |
| 27 |
retVal = 0; |
| 28 |
while (i < opEntry1->numBlends) { |
| 29 |
if (opEntry1->blendValues[i] != opEntry2->blendValues[i]) { |
| 30 |
retVal = 1; |
| 31 |
break; |
| 32 |
} |
| 33 |
i++; |
| 34 |
} |
| 35 |
} |
| 36 |
return retVal; |
| 37 |
} |
| 38 |
|
| 39 |
/* Compare two private dicts to see if they are similar enough to merge. */ |
| 40 |
static int comparePrivateDicts(abfPrivateDict *private1, |
| 41 |
abfPrivateDict *private2) { |
| 42 |
int i; |
| 43 |
|
| 44 |
/* note: for all arrays, unused arrays are initialized with a cnt of 0. */ |
| 45 |
|
| 46 |
if (private1->BlueValues.cnt != private2->BlueValues.cnt) |
| 47 |
return 1; |
| 48 |
|
| 49 |
if (private1->blendValues.BlueValues.cnt != private2->blendValues.BlueValues.cnt) |
| 50 |
return 1; |
| 51 |
|
| 52 |
for (i = 0; i < private1->BlueValues.cnt; i++) |
| 53 |
if ((private1->BlueValues.array[i] != private2->BlueValues.array[i]) || |
| 54 |
((private1->blendValues.BlueValues.cnt > 0) && compareOpEntries(&private1->blendValues.BlueValues.array[i], &private2->blendValues.BlueValues.array[i]))) |
| 55 |
return 1; |
| 56 |
|
| 57 |
if (private1->OtherBlues.cnt != private2->OtherBlues.cnt) |
| 58 |
return 1; |
| 59 |
if (private1->blendValues.OtherBlues.cnt != private2->blendValues.OtherBlues.cnt) |
| 60 |
return 1; |
| 61 |
|
| 62 |
for (i = 0; i < private1->OtherBlues.cnt; i++) |
| 63 |
if ((private1->OtherBlues.array[i] != private2->OtherBlues.array[i]) || |
| 64 |
((private1->blendValues.OtherBlues.cnt > 0) && compareOpEntries(&private1->blendValues.OtherBlues.array[i], &private2->blendValues.OtherBlues.array[i]))) |
| 65 |
return 1; |
| 66 |
|
| 67 |
if (private1->FamilyBlues.cnt != private2->FamilyBlues.cnt) |
| 68 |
return 1; |
| 69 |
if (private1->blendValues.FamilyBlues.cnt != private2->blendValues.FamilyBlues.cnt) |
| 70 |
return 1; |
| 71 |
|
| 72 |
for (i = 0; i < private1->FamilyBlues.cnt; i++) |
| 73 |
if ((private1->FamilyBlues.array[i] != private2->FamilyBlues.array[i]) || |
| 74 |
((private1->blendValues.FamilyBlues.cnt > 0) && compareOpEntries(&private1->blendValues.FamilyBlues.array[i], &private2->blendValues.FamilyBlues.array[i]))) |
| 75 |
return 1; |
| 76 |
|
| 77 |
if (private1->FamilyOtherBlues.cnt != private2->FamilyOtherBlues.cnt) |
| 78 |
return 1; |
| 79 |
if (private1->blendValues.FamilyOtherBlues.cnt != private2->blendValues.FamilyOtherBlues.cnt) |
| 80 |
return 1; |
| 81 |
|
| 82 |
for (i = 0; i < private1->FamilyOtherBlues.cnt; i++) |
| 83 |
if ((private1->FamilyOtherBlues.array[i] != private2->FamilyOtherBlues.array[i]) || |
| 84 |
((private1->blendValues.FamilyOtherBlues.cnt > 0) && compareOpEntries(&private1->blendValues.FamilyOtherBlues.array[i], &private2->blendValues.FamilyOtherBlues.array[i]))) |
| 85 |
return 1; |
| 86 |
|
| 87 |
if (private1->StemSnapH.cnt != private2->StemSnapH.cnt) |
| 88 |
return 1; |
| 89 |
if (private1->blendValues.StemSnapH.cnt != private2->blendValues.StemSnapH.cnt) |
| 90 |
return 1; |
| 91 |
|
| 92 |
for (i = 0; i < private1->StemSnapH.cnt; i++) |
| 93 |
if ((private1->StemSnapH.array[i] != private2->StemSnapH.array[i]) || |
| 94 |
((private1->blendValues.StemSnapH.cnt > 0) && compareOpEntries(&private1->blendValues.StemSnapH.array[i], &private2->blendValues.StemSnapH.array[i]))) |
| 95 |
return 1; |
| 96 |
|
| 97 |
if (private1->StemSnapV.cnt != private2->StemSnapV.cnt) |
| 98 |
return 1; |
| 99 |
if (private1->blendValues.StemSnapV.cnt != private2->blendValues.StemSnapV.cnt) |
| 100 |
return 1; |
| 101 |
|
| 102 |
for (i = 0; i < private1->StemSnapV.cnt; i++) |
| 103 |
if ((private1->StemSnapV.array[i] != private2->StemSnapV.array[i]) || |
| 104 |
((private1->blendValues.StemSnapV.cnt > 0) && compareOpEntries(&private1->blendValues.StemSnapV.array[i], &private2->blendValues.StemSnapV.array[i]))) |
| 105 |
return 1; |
| 106 |
|
| 107 |
if (private1->BlueScale != private2->BlueScale || |
| 108 |
private1->BlueShift != private2->BlueShift || |
| 109 |
private1->BlueFuzz != private2->BlueFuzz || |
| 110 |
private1->StdHW != private2->StdHW || |
| 111 |
private1->StdVW != private2->StdVW || |
| 112 |
(compareOpEntries(&private1->blendValues.BlueScale, &private2->blendValues.BlueScale)) || |
| 113 |
(compareOpEntries(&private1->blendValues.BlueShift, &private2->blendValues.BlueShift)) || |
| 114 |
(compareOpEntries(&private1->blendValues.BlueFuzz, &private2->blendValues.BlueFuzz)) || |
| 115 |
(compareOpEntries(&private1->blendValues.StdHW, &private2->blendValues.StdHW)) || |
| 116 |
(compareOpEntries(&private1->blendValues.StdVW, &private2->blendValues.StdVW)) || |
| 117 |
private1->ForceBold != private2->ForceBold || |
| 118 |
private1->LanguageGroup != private2->LanguageGroup || |
| 119 |
private1->ExpansionFactor != private2->ExpansionFactor) |
| 120 |
return 1; |
| 121 |
|
| 122 |
return 0; |
| 123 |
} |
| 124 |
|
| 125 |
/* Compare two top dicts to see if they are similar enough to merge. |
| 126 |
Assume client has assured that they are valid before call. */ |
| 127 |
int abfCompareTopDicts(abfTopDict *top1, abfTopDict *top2) { |
| 128 |
int firstIsCID = (top1->sup.flags & ABF_CID_FONT) != 0; |
| 129 |
int secondIsCID = (top2->sup.flags & ABF_CID_FONT) != 0; |
| 130 |
|
| 131 |
if (firstIsCID != secondIsCID) |
| 132 |
return 1; |
| 133 |
|
| 134 |
/* For non-CID fonts, compare the private dicts */ |
| 135 |
if (!firstIsCID) { |
| 136 |
if (abfCompareFontDicts(&top1->FDArray.array[0], |
| 137 |
&top2->FDArray.array[0])) |
| 138 |
return 1; |
| 139 |
} |
| 140 |
|
| 141 |
/* Otherwise, we don't compare the font dicts at all; that is handled by |
| 142 |
the destination font module. */ |
| 143 |
|
| 144 |
/* now for the less likely top dict differences */ |
| 145 |
if (top1->isFixedPitch != top2->isFixedPitch || |
| 146 |
top1->ItalicAngle != top2->ItalicAngle || |
| 147 |
top1->StrokeWidth != top2->StrokeWidth) |
| 148 |
return 1; |
| 149 |
|
| 150 |
if (firstIsCID) { |
| 151 |
int i; |
| 152 |
|
| 153 |
if (top1->cid.Registry.ptr && top2->cid.Registry.ptr && |
| 154 |
strcmp(top1->cid.Registry.ptr, top2->cid.Registry.ptr) != 0) |
| 155 |
return 1; |
| 156 |
|
| 157 |
if (top1->cid.Ordering.ptr && top2->cid.Ordering.ptr && |
| 158 |
strcmp(top1->cid.Ordering.ptr, top2->cid.Ordering.ptr) != 0) |
| 159 |
return 1; |
| 160 |
|
| 161 |
if (top1->cid.FontMatrix.cnt != top2->cid.FontMatrix.cnt) |
| 162 |
return 1; |
| 163 |
|
| 164 |
for (i = 0; i < top1->cid.FontMatrix.cnt; i++) |
| 165 |
if (top1->cid.FontMatrix.array[i] != top2->cid.FontMatrix.array[i]) |
| 166 |
return 1; |
| 167 |
} |
| 168 |
|
| 169 |
return 0; |
| 170 |
} |
| 171 |
|
| 172 |
/* Compare two font dicts to see if they are similar enough to merge. */ |
| 173 |
int abfCompareFontDicts(abfFontDict *font1, abfFontDict *font2) { |
| 174 |
int i; |
| 175 |
|
| 176 |
if (font1->PaintType != font2->PaintType) |
| 177 |
return 1; |
| 178 |
|
| 179 |
if (comparePrivateDicts(&font1->Private, &font2->Private)) |
| 180 |
return 1; |
| 181 |
|
| 182 |
if (font1->FontMatrix.cnt != font2->FontMatrix.cnt) |
| 183 |
return 1; |
| 184 |
|
| 185 |
for (i = 0; i < font1->FontMatrix.cnt; i++) |
| 186 |
if (font1->FontMatrix.array[i] != font2->FontMatrix.array[i]) |
| 187 |
return 1; |
| 188 |
|
| 189 |
return 0; |
| 190 |
} |