Skip to content
This repository
Browse code

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

…ist-style-type at the same time
  • Loading branch information...
commit e97f6ae4a4ce02af378f4f3636361b624870b872 1 parent b4df536
Oliver Drobnik authored
3  Classes/DTCSSListStyle.h
@@ -46,6 +46,9 @@ typedef enum
46 46 + (DTCSSListStyle *)discListStyle;
47 47 + (DTCSSListStyle *)inheritedListStyle;
48 48
  49 ++ (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string;
  50 ++ (DTCSSListStylePosition)listStylePositionFromString:(NSString *)string;
  51 +
49 52 - (id)initWithStyles:(NSDictionary *)styles;
50 53
51 54 - (NSString *)prefixWithCounter:(NSInteger)counter;
71 Classes/DTCSSListStyle.m
@@ -8,6 +8,9 @@
8 8
9 9 #import "DTCSSListStyle.h"
10 10
  11 +
  12 +
  13 +
11 14 @interface DTCSSListStyle ()
12 15
13 16 - (void)updateFromStyleDictionary:(NSDictionary *)styles;
@@ -62,12 +65,12 @@ - (id)initWithStyles:(NSDictionary *)styles
62 65 return self;
63 66 }
64 67
65   -// returns NO if not a valid type
66   -- (BOOL)setTypeWithString:(NSString *)string
  68 +// convert string to listStyleType
  69 ++ (DTCSSListStyleType)listStyleTypeFromString:(NSString *)string
67 70 {
68 71 if (!string)
69 72 {
70   - return NO;
  73 + return NSNotFound;
71 74 }
72 75
73 76 // always compare lower case
@@ -75,58 +78,55 @@ - (BOOL)setTypeWithString:(NSString *)string
75 78
76 79 if ([string isEqualToString:@"inherit"])
77 80 {
78   - _type = DTCSSListStyleTypeInherit;
  81 + return DTCSSListStyleTypeInherit;
79 82 }
80 83 else if ([string isEqualToString:@"none"])
81 84 {
82   - _type = DTCSSListStyleTypeNone;
  85 + return DTCSSListStyleTypeNone;
83 86 }
84 87 else if ([string isEqualToString:@"circle"])
85 88 {
86   - _type = DTCSSListStyleTypeCircle;
  89 + return DTCSSListStyleTypeCircle;
87 90 }
88 91 else if ([string isEqualToString:@"decimal"])
89 92 {
90   - _type = DTCSSListStyleTypeDecimal;
  93 + return DTCSSListStyleTypeDecimal;
91 94 }
92 95 else if ([string isEqualToString:@"decimal-leading-zero"])
93 96 {
94   - _type = DTCSSListStyleTypeDecimalLeadingZero;
  97 + return DTCSSListStyleTypeDecimalLeadingZero;
95 98 }
96 99 else if ([string isEqualToString:@"disc"])
97 100 {
98   - _type = DTCSSListStyleTypeDisc;
  101 + return DTCSSListStyleTypeDisc;
99 102 }
100 103 else if ([string isEqualToString:@"upper-alpha"]||[string isEqualToString:@"upper-latin"])
101 104 {
102   - _type = DTCSSListStyleTypeUpperAlpha;
  105 + return DTCSSListStyleTypeUpperAlpha;
103 106 }
104 107 else if ([string isEqualToString:@"lower-alpha"]||[string isEqualToString:@"lower-latin"])
105 108 {
106   - _type = DTCSSListStyleTypeLowerAlpha;
  109 + return DTCSSListStyleTypeLowerAlpha;
107 110 }
108 111 else if ([string isEqualToString:@"plus"])
109 112 {
110   - _type = DTCSSListStyleTypePlus;
  113 + return DTCSSListStyleTypePlus;
111 114 }
112 115 else if ([string isEqualToString:@"underscore"])
113 116 {
114   - _type = DTCSSListStyleTypeUnderscore;
  117 + return DTCSSListStyleTypeUnderscore;
115 118 }
116 119 else
117 120 {
118   - return NO;
  121 + return NSNotFound;
119 122 }
120   -
121   - return YES;
122 123 }
123 124
124   -// returns NO if not a valid type
125   -- (BOOL)setPositionWithString:(NSString *)string
  125 ++ (DTCSSListStylePosition)listStylePositionFromString:(NSString *)string
126 126 {
127 127 if (!string)
128 128 {
129   - return NO;
  129 + return NSNotFound;
130 130 }
131 131
132 132 // always compare lower case
@@ -134,21 +134,47 @@ - (BOOL)setPositionWithString:(NSString *)string
134 134
135 135 if ([string isEqualToString:@"inherit"])
136 136 {
137   - _position = DTCSSListStylePositionInherit;
  137 + return DTCSSListStylePositionInherit;
138 138 }
139 139 else if ([string isEqualToString:@"inside"])
140 140 {
141   - _position = DTCSSListStylePositionInside;
  141 + return DTCSSListStylePositionInside;
142 142 }
143 143 else if ([string isEqualToString:@"outside"])
144 144 {
145   - _position = DTCSSListStylePositionOutside;
  145 + return DTCSSListStylePositionOutside;
146 146 }
147 147 else
148 148 {
  149 + return NSNotFound;
  150 + }
  151 +}
  152 +
  153 +// returns NO if not a valid type
  154 +- (BOOL)setTypeWithString:(NSString *)string
  155 +{
  156 + DTCSSListStyleType type = [DTCSSListStyle listStyleTypeFromString:string];
  157 +
  158 + if (type == NSNotFound)
  159 + {
  160 + return NO;
  161 + }
  162 +
  163 + _type = type;
  164 + return YES;
  165 +}
  166 +
  167 +// returns NO if not a valid type
  168 +- (BOOL)setPositionWithString:(NSString *)string
  169 +{
  170 + DTCSSListStylePosition position = [DTCSSListStyle listStylePositionFromString:string];
  171 +
  172 + if (position == NSNotFound)
  173 + {
149 174 return NO;
150 175 }
151 176
  177 + _position = position;
152 178 return YES;
153 179 }
154 180
@@ -287,4 +313,3 @@ - (NSString *)prefixWithCounter:(NSInteger)counter
287 313 @end
288 314
289 315 // TO DO: Implement image
290   -// TO DO: Implement position
71 Classes/DTCSSStylesheet.m
@@ -7,6 +7,8 @@
7 7 //
8 8
9 9 #import "DTCSSStylesheet.h"
  10 +#import "DTCSSListStyle.h"
  11 +
10 12 #import "DTHTMLElement.h"
11 13 #import "NSString+HTML.h"
12 14
@@ -45,6 +47,65 @@ - (NSString *)description
45 47 return [_styles description];
46 48 }
47 49
  50 +- (void)uncompressShorthands:(NSMutableDictionary *)styles
  51 +{
  52 + NSString *shortHand = [[styles objectForKey:@"list-style"] lowercaseString];
  53 +
  54 + if (shortHand)
  55 + {
  56 + [styles removeObjectForKey:@"list-style"];
  57 +
  58 + if ([shortHand isEqualToString:@"inherit"])
  59 + {
  60 + [styles setObject:@"inherit" forKey:@"list-style-type"];
  61 + [styles setObject:@"inherit" forKey:@"list-style-position"];
  62 + return;
  63 + }
  64 +
  65 + NSArray *components = [shortHand componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
  66 +
  67 + BOOL typeWasSet = NO;
  68 + BOOL positionWasSet = NO;
  69 +
  70 + DTCSSListStyleType listStyleType = NSNotFound;
  71 + DTCSSListStylePosition listStylePosition = NSNotFound;
  72 +
  73 + for (NSString *oneComponent in components)
  74 + {
  75 +
  76 +
  77 + if (!typeWasSet)
  78 + {
  79 + // check if valid type
  80 + listStyleType = [DTCSSListStyle listStyleTypeFromString:oneComponent];
  81 +
  82 + if (listStyleType != NSNotFound)
  83 + {
  84 + [styles setObject:oneComponent forKey:@"list-style-type"];
  85 +
  86 + typeWasSet = YES;
  87 + continue;
  88 + }
  89 + }
  90 +
  91 + if (!positionWasSet)
  92 + {
  93 + // check if valid position
  94 + listStylePosition = [DTCSSListStyle listStylePositionFromString:oneComponent];
  95 +
  96 + if (listStylePosition != NSNotFound)
  97 + {
  98 + [styles setObject:oneComponent forKey:@"list-style-position"];
  99 +
  100 + positionWasSet = YES;
  101 + continue;
  102 + }
  103 + }
  104 + }
  105 +
  106 + return;
  107 + }
  108 +}
48 109
49 110 - (void)addStyleRule:(NSString *)rule withSelector:(NSString*)selectors
50 111 {
@@ -54,7 +115,10 @@ - (void)addStyleRule:(NSString *)rule withSelector:(NSString*)selectors
54 115 {
55 116 NSString *cleanSelector = [selector stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
56 117
57   - NSDictionary *ruleDictionary = [rule dictionaryOfCSSStyles];
  118 + NSMutableDictionary *ruleDictionary = [[[rule dictionaryOfCSSStyles] mutableCopy] autorelease];
  119 +
  120 + // need to uncompress because otherwise we might get shorthands and non-shorthands together
  121 + [self uncompressShorthands:ruleDictionary];
58 122
59 123 NSDictionary *existingRulesForSelector = [self.styles objectForKey:cleanSelector];
60 124
@@ -176,7 +240,10 @@ - (NSDictionary *)mergedStyleDictionaryForElement:(DTHTMLElement *)element
176 240
177 241 if ([styleString length])
178 242 {
179   - NSDictionary *localStyles = [styleString dictionaryOfCSSStyles];
  243 + NSMutableDictionary *localStyles = [[[styleString dictionaryOfCSSStyles] mutableCopy] autorelease];
  244 +
  245 + // need to uncompress because otherwise we might get shorthands and non-shorthands together
  246 + [self uncompressShorthands:localStyles];
180 247
181 248 [tmpDict addEntriesFromDictionary:localStyles];
182 249 }
3  Classes/DTTextAttachment.h
@@ -15,7 +15,8 @@ typedef enum
15 15 DTTextAttachmentTypeImage,
16 16 DTTextAttachmentTypeVideoURL,
17 17 DTTextAttachmentTypeIframe,
18   - DTTextAttachmentTypeObject
  18 + DTTextAttachmentTypeObject,
  19 + DTTextAttachmentTypeGeneric
19 20 } DTTextAttachmentType;
20 21
21 22
14 Classes/NSAttributedString+HTML.m
@@ -289,13 +289,13 @@ - (id)initWithHTML:(NSData *)data options:(NSDictionary *)options documentAttrib
289 289 [currentTag applyStyleDictionary:mergedStyles];
290 290 }
291 291
292   - // // convert CSS Styles into our own style
293   - // NSString *styleString = [currentTag attributeForKey:@"style"];
294   - //
295   - // if (styleString)
296   - // {
297   - // [currentTag parseStyleString:styleString];
298   - // }
  292 + // convert CSS Styles into our own style
  293 +// NSString *styleString = [currentTag attributeForKey:@"style"];
  294 +//
  295 +// if (styleString)
  296 +// {
  297 +// [currentTag parseStyleString:styleString];
  298 +// }
299 299
300 300 if (![currentTag isInline] && !tagOpen && ![currentTag isMeta])
301 301 {
2  Classes/NSAttributedStringRunDelegates.m
@@ -40,7 +40,7 @@ CGFloat embeddedObjectGetWidthCallback(void * context)
40 40 return [(DTTextAttachment *)context displaySize].width;
41 41 }
42 42
43   - return 0;
  43 + return 35;
44 44 }
45 45
46 46 CTRunDelegateRef createEmbeddedObjectRunDelegate(void *context)
16 CoreTextExtensions.xcodeproj/project.pbxproj
@@ -380,8 +380,7 @@
380 380 A7342FF412DC341000044B3C /* NSAttributedString HTML Additions */ = {
381 381 isa = PBXGroup;
382 382 children = (
383   - A7922E8E141621960093FB23 /* DTCSSStylesheet.h */,
384   - A7922E8F141621960093FB23 /* DTCSSStylesheet.m */,
  383 + A7F205451418563300487A9D /* CSS */,
385 384 A73BC3ED12D9F5AD00F064C6 /* NSAttributedString+HTML.h */,
386 385 A73BC3EE12D9F5AD00F064C6 /* NSAttributedString+HTML.m */,
387 386 A7EA579D12E05FBF0045411B /* NSAttributedStringRunDelegates.h */,
@@ -398,8 +397,6 @@
398 397 A78A367312E23C56007CE622 /* NSCharacterSet+HTML.m */,
399 398 A7F2A77313575E700097BF31 /* NSMutableAttributedString+HTML.h */,
400 399 A7F2A77413575E700097BF31 /* NSMutableAttributedString+HTML.m */,
401   - A7C85FDE13F3C460003F0281 /* DTCSSListStyle.h */,
402   - A7C85FDF13F3C460003F0281 /* DTCSSListStyle.m */,
403 400 A7F2A7471357227C0097BF31 /* DTHTMLElement.h */,
404 401 A7F2A7481357227C0097BF31 /* DTHTMLElement.m */,
405 402 );
@@ -515,6 +512,17 @@
515 512 name = Utilities;
516 513 sourceTree = "<group>";
517 514 };
  515 + A7F205451418563300487A9D /* CSS */ = {
  516 + isa = PBXGroup;
  517 + children = (
  518 + A7C85FDE13F3C460003F0281 /* DTCSSListStyle.h */,
  519 + A7C85FDF13F3C460003F0281 /* DTCSSListStyle.m */,
  520 + A7922E8E141621960093FB23 /* DTCSSStylesheet.h */,
  521 + A7922E8F141621960093FB23 /* DTCSSStylesheet.m */,
  522 + );
  523 + name = CSS;
  524 + sourceTree = "<group>";
  525 + };
518 526 B23558DF12E04C3C005EA62F /* Other Sources */ = {
519 527 isa = PBXGroup;
520 528 children = (
4 Resources/CurrentTest.html
... ... @@ -1 +1,3 @@
1   -<!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>
  1 +<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>
  2 +<h2>Disc</h2>
  3 +<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.
Something went wrong with that request. Please try again.