Take scaling into account to fix height calculation
Based on !535 (merged) with the addition of one commit in order to fix size calculation in portrait mode.
Based on !535 (merged) with the addition of one commit in order to fix size calculation in portrait mode.