Permalink
Browse files

Uncompress list-style shorthand to avoid having list-style and e.g. l…

…ist-style-type at the same time
  • Loading branch information...
1 parent b4df536 commit e97f6ae4a4ce02af378f4f3636361b624870b872 @odrobnik odrobnik committed Sep 8, 2011
View
@@ -46,6 +46,9 @@ typedef enum
+ (DTCSSListStyle *)discListStyle;
+ (DTCSSListStyle *)inheritedListStyle;
++ (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string;
++ (DTCSSListStylePosition)listStylePositionFromString:(NSString *)string;
+
- (id)initWithStyles:(NSDictionary *)styles;
- (NSString *)prefixWithCounter:(NSInteger)counter;
View
@@ -8,6 +8,9 @@
#import "DTCSSListStyle.h"
+
+
+
@interface DTCSSListStyle ()
- (void)updateFromStyleDictionary:(NSDictionary *)styles;
@@ -62,93 +65,116 @@ - (id)initWithStyles:(NSDictionary *)styles
return self;
}
-// returns NO if not a valid type
-- (BOOL)setTypeWithString:(NSString *)string
+// convert string to listStyleType
++ (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string
{
if (!string)
{
- return NO;
+ return NSNotFound;
}
// always compare lower case
string = [string lowercaseString];
if ([string isEqualToString:@"inherit"])
{
- _type = DTCSSListStyleTypeInherit;
+ return DTCSSListStyleTypeInherit;
}
else if ([string isEqualToString:@"none"])
{
- _type = DTCSSListStyleTypeNone;
+ return DTCSSListStyleTypeNone;
}
else if ([string isEqualToString:@"circle"])
{
- _type = DTCSSListStyleTypeCircle;
+ return DTCSSListStyleTypeCircle;
}
else if ([string isEqualToString:@"decimal"])
{
- _type = DTCSSListStyleTypeDecimal;
+ return DTCSSListStyleTypeDecimal;
}
else if ([string isEqualToString:@"decimal-leading-zero"])
{
- _type = DTCSSListStyleTypeDecimalLeadingZero;
+ return DTCSSListStyleTypeDecimalLeadingZero;
}
else if ([string isEqualToString:@"disc"])
{
- _type = DTCSSListStyleTypeDisc;
+ return DTCSSListStyleTypeDisc;
}
else if ([string isEqualToString:@"upper-alpha"]||[string isEqualToString:@"upper-latin"])
{
- _type = DTCSSListStyleTypeUpperAlpha;
+ return DTCSSListStyleTypeUpperAlpha;
}
else if ([string isEqualToString:@"lower-alpha"]||[string isEqualToString:@"lower-latin"])
{
- _type = DTCSSListStyleTypeLowerAlpha;
+ return DTCSSListStyleTypeLowerAlpha;
}
else if ([string isEqualToString:@"plus"])
{
- _type = DTCSSListStyleTypePlus;
+ return DTCSSListStyleTypePlus;
}
else if ([string isEqualToString:@"underscore"])
{
- _type = DTCSSListStyleTypeUnderscore;
+ return DTCSSListStyleTypeUnderscore;
}
else
{
- return NO;
+ return NSNotFound;
}
-
- return YES;
}
-// returns NO if not a valid type
-- (BOOL)setPositionWithString:(NSString *)string
++ (DTCSSListStylePosition)listStylePositionFromString:(NSString *)string
{
if (!string)
{
- return NO;
+ return NSNotFound;
}
// always compare lower case
string = [string lowercaseString];
if ([string isEqualToString:@"inherit"])
{
- _position = DTCSSListStylePositionInherit;
+ return DTCSSListStylePositionInherit;
}
else if ([string isEqualToString:@"inside"])
{
- _position = DTCSSListStylePositionInside;
+ return DTCSSListStylePositionInside;
}
else if ([string isEqualToString:@"outside"])
{
- _position = DTCSSListStylePositionOutside;
+ return DTCSSListStylePositionOutside;
}
else
+ {
+ return NSNotFound;
+ }
+}
+
+// returns NO if not a valid type
+- (BOOL)setTypeWithString:(NSString *)string
+{
+ DTCSSListStyleType type = [DTCSSListStyle listStyleTypeFromString:string];
+
+ if (type == NSNotFound)
+ {
+ return NO;
+ }
+
+ _type = type;
+ return YES;
+}
+
+// returns NO if not a valid type
+- (BOOL)setPositionWithString:(NSString *)string
+{
+ DTCSSListStylePosition position = [DTCSSListStyle listStylePositionFromString:string];
+
+ if (position == NSNotFound)
{
return NO;
}
+ _position = position;
return YES;
}
@@ -287,4 +313,3 @@ - (NSString *)prefixWithCounter:(NSInteger)counter
@end
// TO DO: Implement image
-// TO DO: Implement position
View
@@ -7,6 +7,8 @@
//
#import "DTCSSStylesheet.h"
+#import "DTCSSListStyle.h"
+
#import "DTHTMLElement.h"
#import "NSString+HTML.h"
@@ -45,6 +47,65 @@ - (NSString *)description
return [_styles description];
}
+- (void)uncompressShorthands:(NSMutableDictionary *)styles
+{
+ NSString *shortHand = [[styles objectForKey:@"list-style"] lowercaseString];
+
+ if (shortHand)
+ {
+ [styles removeObjectForKey:@"list-style"];
+
+ if ([shortHand isEqualToString:@"inherit"])
+ {
+ [styles setObject:@"inherit" forKey:@"list-style-type"];
+ [styles setObject:@"inherit" forKey:@"list-style-position"];
+ return;
+ }
+
+ NSArray *components = [shortHand componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
+
+ BOOL typeWasSet = NO;
+ BOOL positionWasSet = NO;
+
+ DTCSSListStyleType listStyleType = NSNotFound;
+ DTCSSListStylePosition listStylePosition = NSNotFound;
+
+ for (NSString *oneComponent in components)
+ {
+
+
+ if (!typeWasSet)
+ {
+ // check if valid type
+ listStyleType = [DTCSSListStyle listStyleTypeFromString:oneComponent];
+
+ if (listStyleType != NSNotFound)
+ {
+ [styles setObject:oneComponent forKey:@"list-style-type"];
+
+ typeWasSet = YES;
+ continue;
+ }
+ }
+
+ if (!positionWasSet)
+ {
+ // check if valid position
+ listStylePosition = [DTCSSListStyle listStylePositionFromString:oneComponent];
+
+ if (listStylePosition != NSNotFound)
+ {
+ [styles setObject:oneComponent forKey:@"list-style-position"];
+
+ positionWasSet = YES;
+ continue;
+ }
+ }
+ }
+
+ return;
+ }
+}
- (void)addStyleRule:(NSString *)rule withSelector:(NSString*)selectors
{
@@ -54,7 +115,10 @@ - (void)addStyleRule:(NSString *)rule withSelector:(NSString*)selectors
{
NSString *cleanSelector = [selector stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
- NSDictionary *ruleDictionary = [rule dictionaryOfCSSStyles];
+ NSMutableDictionary *ruleDictionary = [[[rule dictionaryOfCSSStyles] mutableCopy] autorelease];
+
+ // need to uncompress because otherwise we might get shorthands and non-shorthands together
+ [self uncompressShorthands:ruleDictionary];
NSDictionary *existingRulesForSelector = [self.styles objectForKey:cleanSelector];
@@ -176,7 +240,10 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element
if ([styleString length])
{
- NSDictionary *localStyles = [styleString dictionaryOfCSSStyles];
+ NSMutableDictionary *localStyles = [[[styleString dictionaryOfCSSStyles] mutableCopy] autorelease];
+
+ // need to uncompress because otherwise we might get shorthands and non-shorthands together
+ [self uncompressShorthands:localStyles];
[tmpDict addEntriesFromDictionary:localStyles];
}
@@ -15,7 +15,8 @@ typedef enum
DTTextAttachmentTypeImage,
DTTextAttachmentTypeVideoURL,
DTTextAttachmentTypeIframe,
- DTTextAttachmentTypeObject
+ DTTextAttachmentTypeObject,
+ DTTextAttachmentTypeGeneric
} DTTextAttachmentType;
@@ -289,13 +289,13 @@ - (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttrib
[currentTag applyStyleDictionary:mergedStyles];
}
- // // convert CSS Styles into our own style
- // NSString *styleString = [currentTag attributeForKey:@"style"];
- //
- // if (styleString)
- // {
- // [currentTag parseStyleString:styleString];
- // }
+ // convert CSS Styles into our own style
+// NSString *styleString = [currentTag attributeForKey:@"style"];
+//
+// if (styleString)
+// {
+// [currentTag parseStyleString:styleString];
+// }
if (![currentTag isInline] && !tagOpen && ![currentTag isMeta])
{
@@ -40,7 +40,7 @@ CGFloat embeddedObjectGetWidthCallback(void * context)
return [(DTTextAttachment *)context displaySize].width;
}
- return 0;
+ return 35;
}
CTRunDelegateRef createEmbeddedObjectRunDelegate(void *context)
@@ -380,8 +380,7 @@
A7342FF412DC341000044B3C /* NSAttributedString HTML Additions */ = {
isa = PBXGroup;
children = (
- A7922E8E141621960093FB23 /* DTCSSStylesheet.h */,
- A7922E8F141621960093FB23 /* DTCSSStylesheet.m */,
+ A7F205451418563300487A9D /* CSS */,
A73BC3ED12D9F5AD00F064C6 /* NSAttributedString+HTML.h */,
A73BC3EE12D9F5AD00F064C6 /* NSAttributedString+HTML.m */,
A7EA579D12E05FBF0045411B /* NSAttributedStringRunDelegates.h */,
@@ -398,8 +397,6 @@
A78A367312E23C56007CE622 /* NSCharacterSet+HTML.m */,
A7F2A77313575E700097BF31 /* NSMutableAttributedString+HTML.h */,
A7F2A77413575E700097BF31 /* NSMutableAttributedString+HTML.m */,
- A7C85FDE13F3C460003F0281 /* DTCSSListStyle.h */,
- A7C85FDF13F3C460003F0281 /* DTCSSListStyle.m */,
A7F2A7471357227C0097BF31 /* DTHTMLElement.h */,
A7F2A7481357227C0097BF31 /* DTHTMLElement.m */,
);
@@ -515,6 +512,17 @@
name = Utilities;
sourceTree = "<group>";
};
+ A7F205451418563300487A9D /* CSS */ = {
+ isa = PBXGroup;
+ children = (
+ A7C85FDE13F3C460003F0281 /* DTCSSListStyle.h */,
+ A7C85FDF13F3C460003F0281 /* DTCSSListStyle.m */,
+ A7922E8E141621960093FB23 /* DTCSSStylesheet.h */,
+ A7922E8F141621960093FB23 /* DTCSSStylesheet.m */,
+ );
+ name = CSS;
+ sourceTree = "<group>";
+ };
B23558DF12E04C3C005EA62F /* Other Sources */ = {
isa = PBXGroup;
children = (
@@ -1 +1,3 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Times; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: -webkit-auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-tap-highlight-color: rgba(26, 26, 26, 0.300781); -webkit-composition-fill-color: rgba(175, 192, 227, 0.234375); -webkit-composition-frame-color: rgba(77, 128, 180, 0.234375); -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><span class="Apple-style-span" style="color: rgb(51, 51, 51); font-family: Helvetica; font-size: 14px; line-height: 21px; -webkit-text-size-adjust: none; "><p>The reverse-engineering began by inspecting the NSData with a text editor. All I needed was to see the “BPLIST” tag at the beginning to know that this is in fact a binary plist. I deserialized it and was astonished to find that this is simply an NSDictionary.</p><p><a onclick="javascript:pageTracker._trackPageview('/downloads/files/Screen-Shot-2011-09-02-at-5.41.50-PM.png');" href="http://www.cocoanetics.com/files/Screen-Shot-2011-09-02-at-5.41.50-PM.png" style="text-decoration: none; color: rgb(0, 107, 179); "><img class="alignnone size-medium wp-image-5395" title="Deserialized Dictionary" src="http://www.cocoanetics.com/files/Screen-Shot-2011-09-02-at-5.41.50-PM-300x98.png" alt="" width="300" height="98" style="max-width: 100%; height: auto; "></a></p><p>There are several elements to this archive, the most important one being the main contents in a WebArchive class which has mime type “test/html” and is the pure HTML that we are seeking. In addition to that – if you have copied images as well – you see an array of WebRessource elements where each encapsulates a file, typically an image, sometimes a CSS file. Those are basically cached copies. The original HTML still has the web URLs in it, but you could search for the WebResource with the same URL to find the local version.</p></span></span>
+<ul style="font-family: Times; font-size:20px; list-style-type:disc;"><li>4 positions revolver "Direct Drive", for slide (option)</li><li>6 positions revolver "Direct Drive", with integrated counterspindle and 1 driven tool (only for 7 axes version)</li><li>Station with 3 tools for rear working operations (only for 7 axes version)</li></ul>
+<h2>Disc</h2>
+<ul style="font-family: 'Courier New'; font-size:20px;list-style:circle;"><li>4 positions revolver "Direct Drive", for slide (option)</li><li>6 positions revolver "Direct Drive", with integrated counterspindle and 1 driven tool (only for 7 axes version)</li><li>Station with 3 tools for rear working operations (only for 7 axes version)</li></ul>

0 comments on commit e97f6ae

Please sign in to comment.