Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus Hedenström committed Jul 27, 2012
1 parent c5c32de commit a600cb5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
2 changes: 1 addition & 1 deletion PDFKitten/CIDType2Font.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
BOOL identity;
}

@property (nonatomic, assign, getter = isIdentity) BOOL identity;
@property (nonatomic, readonly, getter = isIdentity) BOOL identity;
@end
46 changes: 10 additions & 36 deletions PDFKitten/CIDType2Font.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ - (void)setCIDToGIDMapWithDictionary:(CGPDFDictionaryRef)dict
{
const char *mapName;
if (!CGPDFObjectGetValue(object, kCGPDFObjectTypeName, &mapName)) return;
self.identity = YES;
identity = YES;
}
else if (type == kCGPDFObjectTypeStream)
{
Expand Down Expand Up @@ -42,7 +42,7 @@ - (void)setCIDSystemInfoWithDictionary:(CGPDFDictionaryRef)dict
NSString *registryString = (NSString *) CGPDFStringCopyTextString(registry);
NSString *orderingString = (NSString *) CGPDFStringCopyTextString(ordering);

NSString *cidSystemString = [NSString stringWithFormat:@"%@ (%@) %d", registryString, orderingString, supplement];
NSString *cidSystemString = [NSString stringWithFormat:@"%@ (%@) %ld", registryString, orderingString, supplement];
NSLog(@"%@", cidSystemString);

[registryString release];
Expand All @@ -61,43 +61,17 @@ - (id)initWithFontDictionary:(CGPDFDictionaryRef)dict

- (NSString *)stringWithPDFString:(CGPDFStringRef)pdfString
{
// Note: glyphs descriptions are TrueType

if (self.identity)
unichar *characterIDs = (unichar *) CGPDFStringGetBytePtr(pdfString);
int length = CGPDFStringGetLength(pdfString) / sizeof(unichar);
int magicalOffset = ([self isIdentity] ? 0 : 30);
NSMutableString *unicodeString = [NSMutableString string];
for (int i = 0; i < length; i++)
{
// Use 2-byte CIDToGID identity mapping
size_t length = CGPDFStringGetLength(pdfString);
const unsigned char *cid = CGPDFStringGetBytePtr(pdfString);


NSData *data = [NSData dataWithBytes:cid length:length];
NSLog(@"%@", data);

for (int i = 0; i < length; i+=2)
{
unichar unicodeValue = cid[i] << 8 | cid[i+1];
// unichar unicodeValue = 0x4ea4;
NSLog(@"%C %x", unicodeValue, unicodeValue);
}
unichar unicodeValue = characterIDs[i] + magicalOffset;
[unicodeString appendFormat:@"%C", unicodeValue];
}
else
{
size_t length = CGPDFStringGetLength(pdfString);
const unsigned char *cid = CGPDFStringGetBytePtr(pdfString);

NSMutableString *string = [NSMutableString string];
for (int i = 0; i < length; i+=2)
{
unichar letter = cid[i] << 8 | cid[i+1];
NSLog(@"%C", letter+30);
[string appendFormat:@"%C", letter+30];
}

NSLog(@"==> %@", string);
return string;
}

return @"";
return unicodeString;
}

@synthesize identity;
Expand Down

0 comments on commit a600cb5

Please sign in to comment.