From 4a58953bae7c410321f602ee00dae5c9547d1b89 Mon Sep 17 00:00:00 2001 From: Tyler Freeman Date: Wed, 8 Mar 2023 17:00:18 -0800 Subject: [PATCH] fix(non linear font scaling): avoid trying to apply non-linear font scaling to apps in compatibility mode This reverts an earlier change that may not have been fully thought out, but now has been fully and irrevocably thought out. Fix: 265695259 Test: manual; see bug for steps Change-Id: If808aaa111a21b13a8d56af3fcd47ad31f2c14ed --- .../android/content/res/CompatibilityInfo.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java index ce6e1c7c676fe..08ba5b6c268c8 100644 --- a/core/java/android/content/res/CompatibilityInfo.java +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -557,15 +557,25 @@ public class CompatibilityInfo implements Parcelable { boolean applyToSize) { inoutDm.density = inoutDm.noncompatDensity * invertedRatio; inoutDm.densityDpi = (int) ((inoutDm.noncompatDensityDpi * invertedRatio) + .5f); + // Note: since this is changing the scaledDensity, you might think we also need to change + // inoutDm.fontScaleConverter to accurately calculate non-linear font scaling. But we're not + // going to do that, for a couple of reasons (see b/265695259 for details): + // 1. The first case is only for apps targeting SDK < 4. These ancient apps will just have + // to live with linear font scaling. We don't want to make anything more unpredictable. + // 2. The second case where this is called is for scaling down games. But it is called in + // two situations: + // a. When from ResourcesImpl.updateConfiguration(), we will set the fontScaleConverter + // *after* this method is called. That's the only place where the app will actually + // use the DisplayMetrics for scaling fonts in its resources. + // b. Sometime later by WindowManager in onResume or other windowing events. In this case + // the DisplayMetrics object is never used by the app/resources, so it's ok if + // fontScaleConverter is null because it's not being used to scale fonts anyway. inoutDm.scaledDensity = inoutDm.noncompatScaledDensity * invertedRatio; inoutDm.xdpi = inoutDm.noncompatXdpi * invertedRatio; inoutDm.ydpi = inoutDm.noncompatYdpi * invertedRatio; if (applyToSize) { inoutDm.widthPixels = (int) (inoutDm.widthPixels * invertedRatio + 0.5f); inoutDm.heightPixels = (int) (inoutDm.heightPixels * invertedRatio + 0.5f); - - float fontScale = inoutDm.scaledDensity / inoutDm.density; - inoutDm.fontScaleConverter = FontScaleConverterFactory.forScale(fontScale); } }