Font size for exporting iOS UIView to svg - objective-c

Developing a drawing app on ipad. I am trying to export whatever I draw on canvas (overriding UIView drawRect). Everything works fine except for the text. The problem is with the font size.
I am creating the font using systemFontOfSize:size for drawing on the canvas
and while exporting, I am using using the same size with pt. For example if the size is 15 then in the exported svg, adding a style attribute of text tag as
style="font-size:15pt;"
The Apple documentation says that the systemFontOfSize takes fontSize in points. So whatever I draw on the canvas should be of same size to the size of text in svg (rendered by firefox, Inkscape)
But the size of the text rendered by svg seems to be bigger. I have other drawing on the canvas e.g a rectangle, the size of the text relative to rectangle is bigger in svg than that is displayed on ipad screen. I am also drawing rectangle using point unit on both UIView and svg.
Is there anything I am missing? I am using both places point unit, so DPI should not matter..

Related

React Native Image resizeMode: difference between 'center' and 'contain'?

If you specify dimensions in the style prop of an <Image> component in React Native, adding resizeMode={'contain'} causes the image to preserve its aspect ration and fit entirely in the box whose dimensions you've specified in style. It will also center the image horizontally and vertically within that box.
However, as far as I can tell, center does the same thing as contain. What's the difference?
The difference is how the image fits in the Image container.
Center: the image will be centered in the image container according to the size of the container. It will have uniform space on left, right and top, bottom sides because the image is centered.
Contain: the image is fitted inside the image container keeping the aspect ratio of the image. This means the image will touch the container walls from either width or height or both depending on which side is larger or smaller.
Container is the Image component itself.
In order to see the differences in action, give background color to the Image component.
See the expo slack to better understand it: https://snack.expo.io/#saadqbal/resizemode
From the official document it says:
center:
Center the image in the view along both dimensions. If the
image is larger than the view, scale it down uniformly so that it is
contained in the view.
contain:
Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be
equal to or less than the corresponding dimension of the view (minus
padding).
To get the clear idea about it I would suggest a small trick.
Take a view of 50*50 and put image inside it. Now take rectangle(with more height) and square image. See the difference.
When you use contain it satisfies the following condition
Scale Image Width ≤ Image View Dimension Width
Scale Image Height ≤ Image View Dimension Height
When you use center if image is smaller than the view it will have empty spaces in both x and y directions depending on the image size.
If it is larger then ( unless if you specified the scale ) by default it scales down to contain in it ( this is the situation where it appears to be acting similar to contain )
If the image is larger than the view, scale it down uniformly so that it is contained in the view. Documetation
Check this explanation Understanding “resizeMode” in React Native by Mehran Khan

How to export image (png) containing black rectangle

I have Image, that I made with phone Camera. I need to make some censoring and place black rectangle into Image. I want to create png Image containing black rectangle, that I can send to Backend server.
I know react-native-view-shot
but it only snaps whole display and result is in low resolution.
Is there some other way how to do it? I need to place rectangle into the original image source, not into display snapshot.

Appcelerator Studio - Don't stretch Image

I have a 405x720 image that it is to cover the background image. I've noticed that it stretches the image if the device's screen is smaller than the image. (I'm using a Galaxy S4 to test my apps).
Here's what I have so far:
var fullView = Ti.UI.createImageView({
layout: 'vertical',
width: '100%',
height: '100%',
image: '/images/background.png'
});
I've heard about the clipping technique, however that is only available for iOS and I'd like to have it for both platforms. Is there a way to do this? Or should I try to resize it appropriately? Tips/Suggestions are appreciated!
You should use proper images according to the aspect ratio of screen you are going to run your app on.
You can do this by calculating the width-height ratio of device and then you can decide which image to show on.
But putting a single resolution image directly to cover up the whole screen
is never going to work.
To resize an image, you can use Ti.Blob class' methods after fetching your image using Ti.Filesystem
Also remember that putting an image on whole background takes lot of memory especially in Android. That's why most of the apps do not use complete image to cover up background, rather they use small images wherever necessary and fills up other areas by colors or gradients as required.
But if your requirement is only to use image in background then unload it as soon as you move to different screen and load it again as you are back on it.
Further points to keep note of:
If you set bg image on a View, then it will be fit to cover the dimension of a View. So, if you have a view of width/height to 100%, then image will be fit into it. It means that image size will depend on View's dimension, not the View dimension will depend on image size.
If you set image on ImageView, and suppose you have:
ImageView width = FILL to screen size of 720, then the image height will be automatically decided to keep the aspect ratio. It means that if you have an image of size width=720 and height=400, then the ImageView will be of width=FILL & height=400
Image of size width=1000 and height=800 & ImageView height = 400, then the ImageView will be of width=500 & height=400
The problem is that you're actually telling the image control to load the image on an object that is stretched to the entire width and height of the screen - and when the screen aspect ratio is different than the one you have cropped your image by then you get bad aspect ratio and image looks screwed up.
If you remove either the width or the height, than the aspect ratio of the image will be loaded.
When I want a background image what I found the best way is to make a square image, and then set my ImageView height to Ti.UI.FILL and my width to Ti.UI.SIZE - That way it shows good aspect ratio and side that dont "fit" the screen (width or height) are not shown.

Apply Image in Buttons

As A Begineer I've made a Puzzle game and it's working fine in Iphone Simulators.
But problem occurred when I run it in bigger Screen like IPad Air 2.All the picture aren't fitting perfectly in the buttons
(Note that Images are applied on buttons not in the Background of
buttons)
As image size not fit to given size of button, may be due to size concern of aspect fit property of imageview of button. You can try to scale image proportionally to size of imageview of button and get desire result.
You can refer to this link for scale image as proportionally to desired size.
scale Image in an UIButton to AspectFit?

Drawing scaled emoji icons on iOS

I'm trying to implement my own emoji icon keyboard and have some problems. I'm trying to draw emoji icons at the same size as on native iOS emoji keyboard, but when doing simple drawing (standard unicode characters like "\ue415") icons always appear at original size. When trying to increase the font - emoji icons stay of the same size. When applying CGAffineTransform for scaling - drawn icons are bigger, but pixelated and blurred. How should I go about drawing emoji icons bigger, but sharper?
ei, You can set the font to scaled the emoji icon like this:
label.font = [UIFont fontWithName:#"AppleColorEmoji" size:16.0];
The emoji icons are stored as PNG files in /System/Library/PrivateFrameworks/WebCore.framework (I found this info on the net, but I can't confirm since I don't own a jailbroken iPhone). I don't think it is possible to scale them without loosing quality.
In iOS 5, the png files are gone because they have moved to the same font used in OSX Lion. It's called Apple Color Emoji.