Skip to content

Commit

Permalink
Merge pull request #23 from M2Mobi/feature/OptimizeInlineImage
Browse files Browse the repository at this point in the history
Optimisation of inline images
  • Loading branch information
Basca authored Jan 13, 2017
2 parents 38e37ba + e661ca7 commit f4ee6b2
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 18 deletions.
8 changes: 8 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ target 'markymark_Tests' do

pod 'markymark', :path => '../'
end

post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '2.3'
end
end
end
10 changes: 5 additions & 5 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
PODS:
- markymark (1.0.0)
- markymark (2.0.2)

DEPENDENCIES:
- markymark (from `../`)

EXTERNAL SOURCES:
markymark:
:path: ../
:path: "../"

SPEC CHECKSUMS:
markymark: 98e5f546d669b72a9a0421132435bda772f05a68
markymark: 006ec2919f379d17ebfaafdde6b0ef11da40c9d7

PODFILE CHECKSUM: 481cd97f67bbaaac4fbd503a35c4acb0fe69c1cc
PODFILE CHECKSUM: 19868940cb8798c2b34d2d5eb7bf65010c394bc0

COCOAPODS: 1.1.0.rc.2
COCOAPODS: 1.0.1
6 changes: 4 additions & 2 deletions Example/markymark.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
029A2E5D6800056D702BE822 /* [CP] Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -472,7 +472,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
F220BF3FD9625FD67595F183 /* [CP] Embed Pods Frameworks */ = {
Expand Down Expand Up @@ -609,6 +609,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
};
name = Debug;
};
Expand Down Expand Up @@ -649,6 +650,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 2.3;
VALIDATE_PRODUCT = YES;
};
name = Release;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "20x20",
"scale" : "3x"
},
{
"idiom" : "iphone",
"size" : "29x29",
Expand Down Expand Up @@ -35,4 +45,4 @@
"version" : 1,
"author" : "xcode"
}
}
}
21 changes: 21 additions & 0 deletions Example/markymark/Images.xcassets/appleLogo.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "appleLogo.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "appleLogoSmall.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion Example/markymark/markdown.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ c. Number 3
---
![My Apple](http://images.apple.com/apple-events/static/apple-events/october-2013/video/poster_large.jpg)

Inline image ![Apple logo](appleLogo) Apple logo ![Apple logo](appleLogoSmall)

# Paragraphs
Lorem ipsum *dolor* sit amet, __consectetur__ adipiscing elit. Proin ***aliquet vulputate*** diam. Duis sodales ~~sapien~~ quis ***elementum* posuere**. Duis quam lectus, posueresed [~~pellentesqueaauctor~~](https://m2mobi.com) eu [Velit](https://m2mobi.com).
---
Expand All @@ -71,4 +73,4 @@ On *multiple* lines

``` @Override ```

Or maybe in line `@Override`
Or maybe in line `@Override`
4 changes: 2 additions & 2 deletions markymark.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "markymark"
s.version = "2.0.1"
s.version = "2.0.2"
s.summary = "Markdown parser for iOS"
s.description = <<-DESC
Marky Mark is a parser written in Swift that converts markdown into native views. The way it looks is highly customizable and the supported markdown syntax and tags are easy to extend.
Expand All @@ -15,4 +15,4 @@ Marky Mark is a parser written in Swift that converts markdown into native views

s.source_files = 'markymark/Classes/**/*{.swift}'

end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,23 @@ import Foundation
import UIKit

class TextAttachment: NSTextAttachment {

override func attachmentBoundsForTextContainer(textContainer: NSTextContainer?, proposedLineFragment lineFrag: CGRect, glyphPosition position: CGPoint, characterIndex charIndex: Int) -> CGRect {

var imageSize = CGSize()

let originalImageSize = image?.size ?? CGSize()
let imageRatio = originalImageSize.height / originalImageSize.width

imageSize.width = lineFrag.width
imageSize.height = imageSize.width * imageRatio


let desiredWidth = originalImageSize.height/imageRatio
if desiredWidth > lineFrag.width {
imageSize.width = lineFrag.width
imageSize.height = imageSize.width * imageRatio
} else {
imageSize.height = originalImageSize.height
imageSize.width = desiredWidth
}

return CGRect(origin: CGPoint(), size: imageSize)
}
}

0 comments on commit f4ee6b2

Please sign in to comment.