Calculating how much text will fit in a CGRect before rendering - ios

I've had a good look around and I can't seem to find a good answer for this coding quandary!
I'm laying out pages in an eBook style app for iOS (Swift 3), and I'm trying to pre-calculate how many pages each chapter will need. The two main problems I'm having to tackle are:
The page can be viewed in a two / three column layout
The user can adjust the font size (resulting in more/less pages per chapter)
The tutorials and guides I've reviewed to achieve multi-page columnar layouts seem to require you to actually perform the laying-out of text in the UITextView before you can calculate how much text was used.
My ideal scenario would be a means to say 'I have a font of X size and this CGRect... how much text will fit inside this frame?', but without requiring me to perform the actual rendering of said text into the frame before the calculation is made (as you would using something like UITextView's characterRange(at:...)).
Is there any way to accomplish this? Am I chasing a solution for an unsolvable problem?
Thanks for any assistance that can be offered :o)

Related

Line break in other ways than `NSLineBreakMode` offers (with Core Text?)

I'm creating an application where users are able to change the font and size of certain texts. This makes layout kind of hard. However I've got some predefined texts and I don't like the way they're broken down to lines sometimes.
For example, a text might be: "• Midsommardagen", which might be broken down to what's shown in the image provided.
I think that's ugly and would rather break it down to:
• Midsommar-
dagen
As that's more visually pleasing and fit's better with the Swedish language ("Midsummer day").
What's the best approach to this? Core Text? Any tips on how to realise it with Core Text?

Autolayout - practical layout of complex screens and a conceptual hole

I'm trying hard to drink the Autolayout KoolAid in Xcode 6. I understand the fundamentals. It's solving a set of linear equations for the coordinates and sizes for all on-screen objects. I've watch the videos and read the tutorials. I've gotten it to work.
With all the different devices and screen sizes out there, it seems like a great solution.
So here's a mock-up of my screen:
When I create this simple layout of 5 labels (just the yellow ones for now), I need 20 constraints, right? Height, width, X position and Y position - for each one.
So my constraint list ends up looking like this:
First, I don't see the what that sort order is there, which makes it hard to find things. Worse, that's already a massive number of constraints to look through to find problems.
This can't be a very complex screen in the big scheme of things. What concept am I missing here? What organizational method would help me? If people are doing large screens with many elements, how are they managing the dozens and dozens of constraints?
Note: I don't want to use a table because that seems like overkill - I don't need to scroll, I don't need buttons in cells, and I don't really want to bother styling a table and cells to look like what I've got there in the mock up. This is really just an example of 5 elements on a screen (15 on that screen, actually).

Windows Store App Localized App Bar Buttons Guideline

I have a Windows Store Application. We are using the Multilingual App Toolkit to translate the resources in our app, including the AppBarButtons.
The trouble comes in that some translations of even simple phrases in some languages are incredibly long. What do we do for these buttons? They are near useless if half of the label is ellipsis-ed away ("My bu...").
I've search through the guidelines for what to do in this case and can't seem to find what they expect of us, or what is the best practice for this situation. Should I extend out the width of the buttons? In some cases I have the space to do this. In others, it will make it a bit cramped or I will have to make the buttons not uniform width, which can look bad. Do I make them word wrap? This still cuts some words mid-way in some languages, and can look pretty bad in my opinion. One way to improve that seems to be to align the buttons Top, but that still doesn't fix the mid-word wrap issue.
Does anyone know what the guidelines are for this? Or have any tips as to best practices?
[I'd like to note that, while a part of this question requests opinions as to best practice, the main question I'd like answered is for a guideline specified by Microsoft, as I haven't been able to find one.]

What is the proper image size for an ePub cover page?

I am using the most excellent PHP library ePub to on-the-fly create digital books from HTML stored in my database.
As these are part of a collection, I am including a cover image for every book. Everything works fine in the code but depending upon the device/software interpreting the ePub, the image may get cut off. I have seen 600x800 pixels as a recommended size, but it still cuts it off (for example in Aldiko in Android). Is there a standard size that is recommended in the documentation?
Honestly, I would love a good and readable recommendation for documentation of the ePub format.
So, it seems that Aldiko has the problem, and not the other e-Readers I have tested (Calibre, Overdrive).
After trying various ratios, I found that Aldiko only respects the height:100% style I have called out in the height direction. It doesn't scale the image, only sets the height at 100% of the screen width. I am going to have to go with this being a bug in Aldiko, and keep the recommended 600x800 ratio for maximum resolution.
Another interesting thing I discovered as well; the Aldiko reader didn't recover as well from non-standard HTML. On one of the database entries, a <style> tag inside the <body> disappeared, but the style text did not. This is not the same for the other e-Readers.
The best general advice I found on the internet is Preparing Images for Ebooks Project (PIFEP).

Best font size for Latex Beamer [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am preparing a presentation in latex using the beamer package. I am wondering what font size "pros" who give a lot of presentations use to make sure people in the back of the room can see. The default font size seems a bit small to me.
With beamer, I always use
\documentclass[14pt]{beamer}
The actual font size is larger than 14pt because of the scaling that beamer uses.
The font should be generously large, so that everyone can see it: for typical talk situations font size is not the main constraint, but amount of information being displayed per size.
The advice I generally heard has been to have very few slides with more than 10 to 12 lines of content on them, including the slides heading. The beamer manual suggests that its default of an 11pt font (onto a quite small page, so this is not as small as it sounds) leads to a maximum of around 20 lines on the page, which seems to be rather too high.
By contrast Powerpoint uses a default font size of 17pt, which gives much better amount of information, but often seems to lead, to my taste, to somewhat bombastic presentations.
The middle of this range, around 14pt, seems a good median.
Some further considerations:
I am not a beamer expert. I usually handwrite my slides!
You can justify using rather bigger fonts, to give a point some punch, and sometimes you have a complex idea that is best presented all at once. Variations in the amount of information of the slide should be accompanied by variations in how you present that slide: this is easy with less information, but the risk with more information is that you don't guide the audience through all of what you are presenting properly.
You generally should read out everything on the slide. If this seems silly for some piece of content, it probably shouldn't be there. Don't be tempted to fit large pieces of code on a slide and expect the audience to just absorb what is there: chop out the bits that matter and explain them properly.
When making a presentation your concern should be the readability of projected text. Terms such as 12pt, 16pt are really for type on paper. When projected your text might be 10cm in x-height on the screen in a large hall. There is no good alternative to rehearsing in the room you will be making the presentation in, and checking the legibility of text from the furthest seats.
There are a lot of factors which make rules about type on paper inadequate for guidance on type on a screen. Some of these are:
the difference between the high resolution of laser printers and the generally lower resolution of projectors;
foreground and background colour combinations which work well on paper may work very poorly on screen, and vice-versa;
even the quality of the projection screen has an impact on the readability of text.
This will vary greatly on your screen resolution and on the size of the projection screen.
Charles and I clearly disagree! I've just beamer a fair few times for talks and just left the default sizings as they were and got good results. I believe Beamer is designed with a similar mindset to LaTeX: it uses defaults that are good enough for the intended use.
In my talks, I use Futura as my main font, which is very readable at large sizes. Relevant bits of my standard preamble follow. (I use xelatex btw, which makes font switching much easier)
\usetheme{Copenhagen}
\usefonttheme[onlymath]{serif}
\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\setsansfont[Ligatures={Common}]{Futura}
\setmonofont[Scale=0.8]{Monaco}
You want something "rounder" than you would use for handouts. Also sans-serif. Beyond that it's probably not that big a deal.
I've used Futura and Gill Sans (Keynote's default font) in the past. Calibri (PowerPoint's default in their latest version) is nice. Gotham is a very popular font, too.

Resources