Skip to content

Commit

Permalink
Merge branch 'release-1.6.25'
Browse files Browse the repository at this point in the history
  • Loading branch information
odrobnik committed Oct 8, 2020
2 parents 58a1114 + ee86d6b commit 511a3eb
Show file tree
Hide file tree
Showing 39 changed files with 202 additions and 126 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ build
project.xcworkspace
xcuserdata
.svn
.swiftpm/
.build/
77 changes: 77 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/DTCoreText.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1200"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DTCoreText"
BuildableName = "DTCoreText"
BlueprintName = "DTCoreText"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DTCoreTextTests"
BuildableName = "DTCoreTextTests"
BlueprintName = "DTCoreTextTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "DTCoreText"
BuildableName = "DTCoreText"
BlueprintName = "DTCoreText"
ReferencedContainer = "container:">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
8 changes: 4 additions & 4 deletions Core/Source/DTAttributedTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ - (void)relayoutText
DTAttributedTextView *strongSelf = weakSelf;

// need to reset the layouter because otherwise we get the old framesetter or cached layout frames
strongSelf->_attributedTextContentView.layouter=nil;
strongSelf->_attributedTextContentView.layouter = nil;

// here we're layouting the entire string, might be more efficient to only relayout the paragraphs that contain these attachments
[strongSelf->_attributedTextContentView relayoutText];
Expand Down Expand Up @@ -244,7 +244,7 @@ - (DTAttributedTextContentView *)attributedTextContentView
}

// set text delegate if it was set before instantiation of content view
_attributedTextContentView.delegate = textDelegate;
_attributedTextContentView.delegate = self->_textDelegate;

// pass on setting
_attributedTextContentView.shouldDrawLinks = _shouldDrawLinks;
Expand All @@ -268,7 +268,7 @@ - (DTAttributedTextContentView *)attributedTextContentView

- (void)setBackgroundColor:(DTColor *)newColor
{
if ([newColor alphaComponent]<1.0)
if ([newColor alphaComponent] < 1.0)
{
super.backgroundColor = newColor;
_attributedTextContentView.backgroundColor = [DTColor clearColor];
Expand Down Expand Up @@ -398,7 +398,7 @@ - (void)setTextDelegate:(id<DTAttributedTextContentViewDelegate>)aTextDelegate

- (id<DTAttributedTextContentViewDelegate>)textDelegate
{
return _attributedTextContentView.delegate ?: self->_textDelegate;;
return _attributedTextContentView.delegate ?: self->_textDelegate;
}

- (void)setShouldDrawLinks:(BOOL)shouldDrawLinks
Expand Down
17 changes: 10 additions & 7 deletions Core/Source/DTCSSStylesheet.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,25 @@ + (DTCSSStylesheet *)defaultStyleSheet
{
if (!defaultDTCSSStylesheet)
{

#if SWIFT_PACKAGE // Temporaray fix, since resources in SPM are only supported starting with Swift 5.3
NSString* cssString = @"html{display:block}head{display:none}title{display:none}style{display:none}body{display:block}article,aside,footer,header,hgroup,nav,section{display:block}p{display:block;-webkit-margin-before:1em;-webkit-margin-after:1em;-webkit-margin-start:0;-webkit-margin-end:0}ul,menu,dir{display:block;list-style-type:disc;-webkit-margin-before:1em;-webkit-margin-after:1em;-webkit-margin-start:0;-webkit-margin-end:0;-webkit-padding-start:27px}li{display:list-item}ol{display:block;list-style-type:decimal;-webkit-margin-before:1em;-webkit-margin-after:1em;-webkit-margin-start:0;-webkit-margin-end:0;-webkit-padding-start:27px}ul ul,ol ul{list-style-type:circle}ol ol ul,ol ul ul,ul ol ul,ul ul ul{list-style-type:square}code{font-family:Courier}pre,xmp,plaintext,listing{display:block;font-family:monospace;white-space:pre;margin:1em 0px}a{color:#0000EE;text-decoration:underline}a:active{color:#FF0000}center{text-align:center;display:block}strong,b{font-weight:bolder}i,em{font-style:italic}u{text-decoration:underline}big{font-size:bigger}small{font-size:smaller}sub{font-size:smaller;vertical-align:sub}sup{font-size:smaller;vertical-align:super}s,strike,del{text-decoration:line-through}tt,code,kbd,samp{font-family:monospace}pre,xmp,plaintext,listing{display:block;font-family:monospace;white-space:pre;margin-top:1em;margin-right:0;margin-bottom:1em;margin-left:0}h1{display:block;font-size:2em;-webkit-margin-before:.67em;-webkit-margin-after:.67em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}h2{display:block;font-size:1.5em;-webkit-margin-before:.83em;-webkit-margin-after:.83em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}h3{display:block;font-size:1.17em;-webkit-margin-before:1em;-webkit-margin-after:1em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}h4{display:block;-webkit-margin-before:1.33em;-webkit-margin-after:1.33em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}h5{display:block;font-size:.83em;-webkit-margin-before:1.67em;-webkit-margin-after:1.67em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}h6{display:block;font-size:.67em;-webkit-margin-before:2.33em;-webkit-margin-after:2.33em;-webkit-margin-start:0;-webkit-margin-end:0;font-weight:bold}div{display:block}link{display:none}meta{display:none}script{display:none}hr{display:block;-webkit-margin-before:0.5em;-webkit-margin-after:0.5em;-webkit-margin-start:auto;-webkit-margin-end:auto;border-style:inset;border-width:1px}table{display:table;border-collapse:separate;border-spacing:2px;border-color:gray}";

#if SWIFT_PACKAGE
// get resource bundle via macro
NSString *path = [SWIFTPM_MODULE_BUNDLE pathForResource:@"default" ofType:@"css"];
#else
NSBundle *bundle = [NSBundle bundleForClass:self];
NSString *path = [bundle pathForResource:@"default" ofType:@"css"];
NSBundle *bundle = [NSBundle bundleForClass:self];
NSString *path = [[NSBundle bundleForClass:self] pathForResource:@"default" ofType:@"css"];

// Cocoapods uses a separate Resources bundle to include default.css
if (!path)
{
NSString *resourcesBundlePath = [bundle pathForResource:@"Resources" ofType:@"bundle"];
NSBundle *resourcesBundle = [NSBundle bundleWithPath:resourcesBundlePath];
path = [resourcesBundle pathForResource:@"default" ofType:@"css"];
}
NSString *cssString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
#endif

NSAssert(path != nil, @"Missing default.css");

NSString *cssString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];

defaultDTCSSStylesheet = [[DTCSSStylesheet alloc] initWithStyleBlock:cssString];
}
Expand Down
1 change: 1 addition & 0 deletions Core/Source/DTCoreText.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#import "NSString+CSS.h"
#import "NSString+HTML.h"
#import "NSString+Paragraphs.h"
#import "NSNumber+RomanNumerals.h"

// parsing classes
#import "DTHTMLParserNode.h"
Expand Down
37 changes: 35 additions & 2 deletions Core/Source/DTCoreTextFontDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,7 @@ - (CTFontRef)_findOrMakeMatchingFont
{
CTFontDescriptorRef searchingFontDescriptor = NULL;
CTFontDescriptorRef matchingFontDescriptor = NULL;
CFArrayRef matchingFontDescriptors = NULL;
CTFontRef matchingFont = NULL;

// check the cache first
Expand Down Expand Up @@ -602,8 +603,35 @@ - (CTFontRef)_findOrMakeMatchingFont
[mandatoryAttributes addObject:(id)kCTFontFeaturesAttribute];
}

// do the search
matchingFontDescriptor = CTFontDescriptorCreateMatchingFontDescriptor(searchingFontDescriptor, (__bridge CFSetRef)mandatoryAttributes);
matchingFontDescriptors = CTFontDescriptorCreateMatchingFontDescriptors(searchingFontDescriptor, (__bridge CFSetRef)mandatoryAttributes);

if (matchingFontDescriptors) {
CFIndex count = CFArrayGetCount(matchingFontDescriptors);
if (count == 1) {
matchingFontDescriptor = CTFontDescriptorCreateMatchingFontDescriptor(searchingFontDescriptor, (__bridge CFSetRef)mandatoryAttributes);
} else {
CFIndex i = 0;
for (i=0; i<count; i++) {
CTFontDescriptorRef currentFontDescriptor = CFArrayGetValueAtIndex(matchingFontDescriptors, i);
CFDictionaryRef traits = CTFontDescriptorCopyAttribute(currentFontDescriptor, kCTFontTraitsAttribute);
NSDictionary *traitsDictionary = CFBridgingRelease(traits);

BOOL hasSlantValue = [traitsDictionary[@"NSCTFontSlantTrait"] boolValue];
BOOL hasBoldValue = [traitsDictionary[@"NSCTFontWeightTrait"] boolValue];

BOOL hasMatchingBoldTrait = hasBoldValue == self.boldTrait;
BOOL hasMatchingItalicTrait = hasSlantValue == self.italicTrait;

if (hasMatchingBoldTrait && hasMatchingItalicTrait) {
matchingFontDescriptor = currentFontDescriptor;
CFRetain(matchingFontDescriptor);

// take first one that fits
break;
}
}
}
}

if (!matchingFontDescriptor)
{
Expand Down Expand Up @@ -645,6 +673,11 @@ - (CTFontRef)_findOrMakeMatchingFont
CFRelease(searchingFontDescriptor);
}

if (matchingFontDescriptors)
{
CFRelease(matchingFontDescriptors);
}

// check if we indeed got an oblique font if we wanted one
if (matchingFont && self.italicTrait && ![self _fontIsOblique:matchingFont])
{
Expand Down
5 changes: 1 addition & 4 deletions Core/Source/DTHTMLAttributedStringBuilder.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,7 @@ - (BOOL)_buildString
if (defaultFontName) {
_defaultFontDescriptor.fontName = defaultFontName;
}
else
{
_defaultFontDescriptor.fontName = @"TimesNewRomanPSMT";
}


_defaultLinkColor = [_options objectForKey:DTDefaultLinkColor];

Expand Down
1 change: 1 addition & 0 deletions Core/include/DTCoreText/NSNumber+RomanNumerals.h
Loading

0 comments on commit 511a3eb

Please sign in to comment.