-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Le Xuan Quynh
committed
Aug 8, 2021
1 parent
8105ec4
commit da3b49d
Showing
78 changed files
with
1,616 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// NSAttributedString+RichTextEditor.h | ||
// RichTextEdtor | ||
// | ||
// Created by Aryan Gh on 7/21/13. | ||
// Copyright (c) 2013 Aryan Ghassemi. All rights reserved. | ||
// | ||
// https://github.com/aryaxt/iOS-Rich-Text-Editor | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "UIFont+RichTextEditor.h" | ||
|
||
@interface NSAttributedString (RichTextEditor) | ||
|
||
- (NSRange)firstParagraphRangeFromTextRange:(NSRange)range; | ||
- (NSArray *)rangeOfParagraphsFromTextRange:(NSRange)textRange; | ||
- (NSString *)htmlString; | ||
|
||
@end |
220 changes: 220 additions & 0 deletions
220
QRichTextView/Classes/NSAttributedString+RichTextEditor.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,220 @@ | ||
// | ||
// NSAttributedString+RichTextEditor.m | ||
// RichTextEdtor | ||
// | ||
// Created by Aryan Gh on 7/21/13. | ||
// Copyright (c) 2013 Aryan Ghassemi. All rights reserved. | ||
// | ||
// https://github.com/aryaxt/iOS-Rich-Text-Editor | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import "NSAttributedString+RichTextEditor.h" | ||
|
||
@implementation NSAttributedString (RichTextEditor) | ||
|
||
#pragma mark - Public MEthods - | ||
|
||
- (NSRange)firstParagraphRangeFromTextRange:(NSRange)range | ||
{ | ||
NSInteger start = -1; | ||
NSInteger end = -1; | ||
NSInteger length = 0; | ||
|
||
NSInteger startingRange = (range.location == self.string.length || [self.string characterAtIndex:range.location] == '\n') ? | ||
range.location-1 : | ||
range.location; | ||
|
||
for (int i=startingRange ; i>=0 ; i--) | ||
{ | ||
char c = [self.string characterAtIndex:i]; | ||
if (c == '\n') | ||
{ | ||
start = i+1; | ||
break; | ||
} | ||
} | ||
|
||
start = (start == -1) ? 0 : start; | ||
|
||
NSInteger moveForwardIndex = (range.location > start) ? range.location : start; | ||
|
||
for (int i=moveForwardIndex; i<= self.string.length-1 ; i++) | ||
{ | ||
char c = [self.string characterAtIndex:i]; | ||
if (c == '\n') | ||
{ | ||
end = i; | ||
break; | ||
} | ||
} | ||
|
||
end = (end == -1) ? self.string.length : end; | ||
length = end - start; | ||
|
||
return NSMakeRange(start, length); | ||
} | ||
|
||
- (NSArray *)rangeOfParagraphsFromTextRange:(NSRange)textRange | ||
{ | ||
NSMutableArray *paragraphRanges = [NSMutableArray array]; | ||
NSInteger rangeStartIndex = textRange.location; | ||
|
||
while (true) | ||
{ | ||
NSRange range = [self firstParagraphRangeFromTextRange:NSMakeRange(rangeStartIndex, 0)]; | ||
rangeStartIndex = range.location + range.length + 1; | ||
|
||
[paragraphRanges addObject:[NSValue valueWithRange:range]]; | ||
|
||
if (range.location + range.length >= textRange.location + textRange.length) | ||
break; | ||
} | ||
|
||
return paragraphRanges; | ||
} | ||
|
||
- (NSString *)htmlString | ||
{ | ||
NSMutableString *htmlString = [NSMutableString string]; | ||
NSArray *paragraphRanges = [self rangeOfParagraphsFromTextRange:NSMakeRange(0, self.string.length-1)]; | ||
|
||
for (int i=0 ; i<paragraphRanges.count ; i++) | ||
{ | ||
NSValue *value = [paragraphRanges objectAtIndex:i]; | ||
NSRange range = [value rangeValue]; | ||
NSDictionary *paragraphDictionary = [self attributesAtIndex:range.location effectiveRange:nil]; | ||
NSParagraphStyle *paragraphStyle = [paragraphDictionary objectForKey:NSParagraphStyleAttributeName]; | ||
NSString *textAlignmentString = [self htmlTextAlignmentString:paragraphStyle.alignment]; | ||
|
||
[htmlString appendString:@"<p "]; | ||
|
||
if (textAlignmentString) | ||
[htmlString appendFormat:@"align=\"%@\" ", textAlignmentString]; | ||
|
||
[htmlString appendFormat:@"style=\""]; | ||
|
||
if (paragraphStyle.firstLineHeadIndent > 0) | ||
[htmlString appendFormat:@"text-indent:%.0fpx; ", paragraphStyle.firstLineHeadIndent - paragraphStyle.headIndent]; | ||
|
||
if (paragraphStyle.headIndent > 0) | ||
[htmlString appendFormat:@"margin-left:%.0fpx; ", paragraphStyle.headIndent]; | ||
|
||
|
||
[htmlString appendString:@" \">"]; | ||
|
||
[self enumerateAttributesInRange:range | ||
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired | ||
usingBlock:^(NSDictionary *dictionary, NSRange range, BOOL *stop){ | ||
|
||
NSMutableString *fontString = [NSMutableString string]; | ||
UIFont *font = [dictionary objectForKey:NSFontAttributeName]; | ||
UIColor *foregroundColor = [dictionary objectForKey:NSForegroundColorAttributeName]; | ||
UIColor *backGroundColor = [dictionary objectForKey:NSBackgroundColorAttributeName]; | ||
NSNumber *underline = [dictionary objectForKey:NSUnderlineStyleAttributeName]; | ||
BOOL hasUnderline = (!underline || underline.intValue == NSUnderlineStyleNone) ? NO :YES; | ||
NSNumber *strikeThrough = [dictionary objectForKey:NSStrikethroughStyleAttributeName]; | ||
BOOL hasStrikeThrough = (!strikeThrough || strikeThrough.intValue == NSUnderlineStyleNone) ? NO :YES; | ||
|
||
[fontString appendFormat:@"<font "]; | ||
[fontString appendFormat:@"face=\"%@\" ", font.familyName]; | ||
|
||
// Begin style | ||
[fontString appendString:@" style=\" "]; | ||
|
||
[fontString appendFormat:@"font-size:%.0fpx; ", font.pointSize]; | ||
|
||
if (foregroundColor && [foregroundColor isKindOfClass:[UIColor class]]) | ||
[fontString appendFormat:@"color:%@; ", [self htmlRgbColor:foregroundColor]]; | ||
|
||
if (backGroundColor && [backGroundColor isKindOfClass:[UIColor class]]) | ||
[fontString appendFormat:@"background-color:%@; ", [self htmlRgbColor:backGroundColor]]; | ||
|
||
[fontString appendString:@"\" "]; | ||
// End Style | ||
|
||
[fontString appendString:@">"]; | ||
[fontString appendString:[[self.string substringFromIndex:range.location] substringToIndex:range.length]]; | ||
[fontString appendString:@"</font>"]; | ||
|
||
if ([font isBold]) | ||
{ | ||
[fontString insertString:@"<b>" atIndex:0]; | ||
[fontString insertString:@"</b>" atIndex:fontString.length]; | ||
} | ||
|
||
if ([font isItalic]) | ||
{ | ||
[fontString insertString:@"<i>" atIndex:0]; | ||
[fontString insertString:@"</i>" atIndex:fontString.length]; | ||
} | ||
|
||
if (hasUnderline) | ||
{ | ||
[fontString insertString:@"<u>" atIndex:0]; | ||
[fontString insertString:@"</u>" atIndex:fontString.length]; | ||
} | ||
|
||
if (hasStrikeThrough) | ||
{ | ||
[fontString insertString:@"<strike>" atIndex:0]; | ||
[fontString insertString:@"</strike>" atIndex:fontString.length]; | ||
} | ||
|
||
|
||
[htmlString appendString:fontString]; | ||
}]; | ||
|
||
[htmlString appendString:@"</p>"]; | ||
} | ||
|
||
return htmlString; | ||
} | ||
|
||
#pragma mark - Helper Methods - | ||
|
||
- (NSString *)htmlTextAlignmentString:(NSTextAlignment)textAlignment | ||
{ | ||
switch (textAlignment) | ||
{ | ||
case NSTextAlignmentLeft: | ||
return @"left"; | ||
|
||
case NSTextAlignmentCenter: | ||
return @"center"; | ||
|
||
case NSTextAlignmentRight: | ||
return @"right"; | ||
|
||
case NSTextAlignmentJustified: | ||
return @"justify"; | ||
|
||
default: | ||
return nil; | ||
} | ||
} | ||
|
||
- (NSString *)htmlRgbColor:(UIColor *)color | ||
{ | ||
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; | ||
[color getRed:&red green:&green blue:&blue alpha:&alpha]; | ||
return [NSString stringWithFormat:@"rgb(%d,%d,%d)",(int)(red*255.0), (int)(green*255.0), (int)(blue*255.0)]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* UIBarButtonItem+WEPopover.h | ||
* WEPopover | ||
* | ||
* Created by Werner Altewischer on 07/05/11. | ||
* Copyright 2010 Werner IT Consultancy. All rights reserved. | ||
* | ||
*/ | ||
|
||
#import <Foundation/Foundation.h> | ||
#import <UIKit/UIKit.h> | ||
|
||
@interface UIBarButtonItem(WEPopover) | ||
|
||
- (CGRect)frameInView:(UIView *)v; | ||
- (UIView *)superview; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* UIBarButtonItem+WEPopover.m | ||
* WEPopover | ||
* | ||
* Created by Werner Altewischer on 07/05/11. | ||
* Copyright 2010 Werner IT Consultancy. All rights reserved. | ||
* | ||
*/ | ||
|
||
#import "UIBarButtonItem+WEPopover.h" | ||
|
||
@implementation UIBarButtonItem(WEPopover) | ||
|
||
- (CGRect)frameInView:(UIView *)v { | ||
|
||
UIView *theView = self.customView; | ||
if (!theView && [self respondsToSelector:@selector(view)]) { | ||
theView = [self performSelector:@selector(view)]; | ||
} | ||
|
||
UIView *parentView = theView.superview; | ||
NSArray *subviews = parentView.subviews; | ||
|
||
NSUInteger indexOfView = [subviews indexOfObject:theView]; | ||
NSUInteger subviewCount = subviews.count; | ||
|
||
if (subviewCount > 0 && indexOfView != NSNotFound) { | ||
UIView *button = [parentView.subviews objectAtIndex:indexOfView]; | ||
return [button convertRect:button.bounds toView:v]; | ||
} else { | ||
return CGRectZero; | ||
} | ||
} | ||
|
||
- (UIView *)superview { | ||
|
||
UIView *theView = self.customView; | ||
if (!theView && [self respondsToSelector:@selector(view)]) { | ||
theView = [self performSelector:@selector(view)]; | ||
} | ||
|
||
UIView *parentView = theView.superview; | ||
return parentView; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// UIFont+RichTextEditor.h | ||
// RichTextEdtor | ||
// | ||
// Created by Aryan Gh on 7/21/13. | ||
// Copyright (c) 2013 Aryan Ghassemi. All rights reserved. | ||
// | ||
// https://github.com/aryaxt/iOS-Rich-Text-Editor | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <CoreText/CoreText.h> | ||
|
||
@interface UIFont (RichTextEditor) | ||
|
||
+ (NSString *)postscriptNameFromFullName:(NSString *)fullName; | ||
+ (UIFont *)fontWithName:(NSString *)name size:(CGFloat)size boldTrait:(BOOL)isBold italicTrait:(BOOL)isItalic; | ||
- (UIFont *)fontWithBoldTrait:(BOOL)bold italicTrait:(BOOL)italic andSize:(CGFloat)size; | ||
- (UIFont *)fontWithBoldTrait:(BOOL)bold andItalicTrait:(BOOL)italic; | ||
- (BOOL)isBold; | ||
- (BOOL)isItalic; | ||
|
||
@end |
Oops, something went wrong.