Skip to content

Commit

Permalink
Deal with merge
Browse files Browse the repository at this point in the history
  • Loading branch information
KurtCode committed Nov 26, 2012
1 parent d1c3089 commit a83f5f4
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 128 deletions.
2 changes: 1 addition & 1 deletion PDFKitten/CMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ extern NSValue *rangeValue(unsigned int from, unsigned int to);
- (id)initWithString:(NSString *)string;

/* Unicode mapping for character ID */
- (NSString *)unicodeCharacter:(unichar)cid;
- (unichar)unicodeCharacter:(unichar)cid;

- (unichar)cidCharacter:(unichar)unicode;

Expand Down
54 changes: 3 additions & 51 deletions PDFKitten/CMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,6 @@ - (NSSet *)operators

- (Operator *)operatorWithStartingToken:(NSString *)token {
NSString *content = nil;
static NSString *endToken = @"endbfchar";
[scanner scanUpToString:endToken intoString:&content];
NSCharacterSet *newLineSet = [NSCharacterSet newlineCharacterSet];
NSCharacterSet *tagSet = [NSCharacterSet characterSetWithCharactersInString:@"<>"];
NSString *separatorString = @"> <";
Expand Down Expand Up @@ -166,19 +164,12 @@ - (Operator *)operatorWithStartingToken:(NSString *)token {
scanner = [NSScanner scannerWithString:[parts objectAtIndex:1]];
[scanner scanHexInt:&to];
NSNumber *toNumber = [NSNumber numberWithInt:to];
[chars setObject:toNumber forKey:fromNumber];
[chars setObject:toNumber forKey:fromNumber];

}
}

}

- (void)scanCMap:(NSScanner *)scanner
{
for (Operator *op in self.operators)
{
if ([op.start isEqualToString:token]) return op;
}
return nil;
return nil;
}

/**!
Expand Down Expand Up @@ -261,15 +252,6 @@ - (unsigned int)valueOfTag:(NSString *)tagString
return numericValue;
}

- (void)scanning:(NSString *text) {
NSLog(@"%@", text);
NSScanner *scanner = [NSScanner scannerWithString:text];
[scanner scanUpToString:@"begincmap" intoString:nil];
[scanner scanString:@"begincmap" intoString:nil];
NSLog(@"%d", scanner.scanLocation);
[self scanCMap:scanner];
}

/**!
* Code space ranges are pairs of hex numbers:
* <from> <to>
Expand Down Expand Up @@ -371,36 +353,6 @@ - (NSMutableDictionary *)characterRangeMappings {
self.characterRangeMappings = [NSMutableDictionary dictionary];
}
return characterRangeMappings;

- (NSString *)unicodeCharacter:(unichar)cid
{
NSString *result = [NSString stringWithFormat: @"%C", cid];
NSDictionary *dict = [self rangeWithCharacter:cid];
if (dict)
{
NSUInteger internalOffset = cid - [[dict objectForKey:@"First"] intValue];
result = [NSString stringWithFormat: @"%C", [[dict objectForKey:@"Offset"] intValue] + internalOffset];
}
else if (chars)
{
NSNumber *fromChar = [NSNumber numberWithInt: cid];
NSObject *to = [chars objectForKey: fromChar];
if ([to isKindOfClass: [NSNumber class]]) {
NSNumber *toChar = [chars objectForKey: fromChar];
result = [NSString stringWithFormat: @"%C", [toChar intValue]];
} else if ([to isKindOfClass: [NSArray class]]) {
NSArray *toArray = (NSArray *)to;
NSNumber *nextChar;
NSMutableString *temp = [[NSMutableString alloc] initWithCapacity: [toArray count]];
for (int i = 0; i < [toArray count]; i++) {
nextChar = [toArray objectAtIndex: i];
[temp appendFormat: @"%C", [nextChar intValue]];
}
result = [NSString stringWithString: temp];
[temp release];
}
}
return result;
}

- (unichar)cidCharacter:(unichar)unicode
Expand Down
4 changes: 3 additions & 1 deletion PDFKitten/CompositeFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ - (void)setWidthsWithArray:(CGPDFArrayRef)widthsArray
{
NSUInteger length = CGPDFArrayGetCount(widthsArray);
int idx = 0;
CGPDFObjectRef nextObject = nil;
while (idx < length)
{
CGPDFInteger baseCid = 0;
CGPDFArrayGetInteger(widthsArray, idx, &baseCid);

CGPDFObjectRef integerOrArray = nil;
CGPDFInteger firstCharacter = 0;
CGPDFArrayGetObject(widthsArray, idx + 1, &integerOrArray);
if (CGPDFObjectGetType(integerOrArray) == kCGPDFObjectTypeInteger)
{
Expand All @@ -50,7 +52,7 @@ - (void)setWidthsWithArray:(CGPDFArrayRef)widthsArray
{
NSNumber *key = [NSNumber numberWithInt:firstCharacter+index];
NSNumber *val = [NSNumber numberWithInt:width];
[widthsDict setObject:val forKey:key];
[widths setObject:val forKey:key];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion PDFKitten/Font.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ - (NSString *)unicodeWithPDFString:(CGPDFStringRef)pdfString
for (int i = 0; i < length; i++)
{
const unsigned char cid = bytes[i];
[unicodeString appendString: [self.toUnicode unicodeCharacter:cid]];
[unicodeString appendFormat:@"%C", [self.toUnicode unicodeCharacter:cid]];
}
return unicodeString;
}
Expand Down
4 changes: 1 addition & 3 deletions PDFKitten/SimpleFont.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ - (NSString *)stringWithPDFString:(CGPDFStringRef)pdfString
for (int i = 0; i < [str length]; i++)
{
unichar cid = [str characterAtIndex:i];
// [unicodeString appendFormat:@"%C", [self.toUnicode unicodeCharacter:cid]];
[unicodeString appendString: [self.toUnicode unicodeCharacter:cid]];

[unicodeString appendFormat:@"%C", [self.toUnicode unicodeCharacter:cid]];
}

[str release];
Expand Down
70 changes: 0 additions & 70 deletions PDFKitten/StringDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,76 +179,6 @@ - (NSString *)stringByExpandingLigatures:(NSString *)string font:(Font *)font
return string;
}

/* Feed a string into the state machine */
- (NSString *)appendPDFString:(CGPDFStringRef)string withFont:(Font *)font
{
NSString *unicodeString = [font unicodeWithPDFString:string];
NSString *unicodeLower = [unicodeString lowercaseString];

[unicodeContent appendString:unicodeString];

for (int i = 0; i < [unicodeString length]; i++)
{
NSString *needleString = [NSString stringWithFormat:@"%C", [unicodeLower characterAtIndex:i]];

// Expand ligatures to separate characters
needleString = [self stringByExpandingLigatures:needleString font:font];

BOOL isFirst = (self.keywordPosition == 0);
BOOL isLast;
if ([self append:needleString isLast:&isLast font:font])
{
if (isFirst)
{
// Tell delegate first characher was scanned.
[self didStartDetectingNeedle];
}

// Tell delegate another character was scanned.
// It is critical that this message be sent AFTER the first character
// of the keyword has been detected, and BEFORE the last character is
// detected, such that all characters of the keyword fall within the
// messages corresponding to the start and end of the detected string.
[self didScanCharacter:[unicodeString characterAtIndex:i]];

if (isLast)
{
// The entire string was found. Inform the delegate
// and reset for further scanning.
[self didFindNeedle];
[self reset];
}
}
else
{
// Reset and try again!
[self reset];

// This covers the case where the character does not match the current
// position in the keyword, but matches the first.
if ([self append:needleString isLast:&isLast font:font])
{
[self didStartDetectingNeedle];

[self didScanCharacter:[unicodeString characterAtIndex:i]];

if (isLast)
{
[self didFindNeedle];
[self reset];
}
}
else
{
// Tell delegate another character was scanned,
// and reset in case part of the keyword was already matched.
[self didScanCharacter:[unicodeString characterAtIndex:i]];
}
}
}
return unicodeString;
}

#pragma mark -
#pragma mark Memory Management

Expand Down
3 changes: 2 additions & 1 deletion PDFKitten/Type0Font.m
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ - (NSString *)unicodeWithPDFString:(CGPDFStringRef)pdfString {
if (self.toUnicode) {
result = [[[NSMutableString alloc] initWithCapacity: [descendantResult length]] autorelease];
for (int i = 0; i < [descendantResult length]; i++) {
[result appendString: [self.toUnicode unicodeCharacter:[descendantResult characterAtIndex:i]]];
unichar character = [self.toUnicode unicodeCharacter:[descendantResult characterAtIndex:i]];
[result appendFormat:@"%C", character];
}
} else {
result = [NSMutableString stringWithString: descendantResult];
Expand Down

0 comments on commit a83f5f4

Please sign in to comment.