How To Get Font Size in HTML

Just grabbing the style.fontSize of an element may not work. If the font-size is defined by a stylesheet, this will report “” (empty string). You should use window.getComputedStyle. var el = document.getElementById(‘foo’); var style = window.getComputedStyle(el, null).getPropertyValue(‘font-size’); var fontSize = parseFloat(style); // now you have a proper float for the font size (yes, it can … Read more

Auto-fit TextView for Android

Thanks to MartinH’s simple fix here, this code also takes care of android:drawableLeft, android:drawableRight, android:drawableTop and android:drawableBottom tags. My answer here should make you happy Auto Scale TextView Text to Fit within Bounds I have modified your test case: @Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); final ViewGroup container = (ViewGroup) findViewById(R.id.container); findViewById(R.id.button1).setOnClickListener(new … Read more

How to change the font size on a matplotlib plot

From the matplotlib documentation, font = {‘family’ : ‘normal’, ‘weight’ : ‘bold’, ‘size’ : 22} matplotlib.rc(‘font’, **font) This sets the font of all items to the font specified by the kwargs object, font. Alternatively, you could also use the rcParams update method as suggested in this answer: matplotlib.rcParams.update({‘font.size’: 22}) or import matplotlib.pyplot as plt plt.rcParams.update({‘font.size’: … Read more

How to adjust text font size to fit textview

The solution below incorporates all of the suggestions here. It starts with what was originally posted by Dunni. It uses a binary search like gjpc’s, but it is a bit more readable. It also include’s gregm’s bug fixes and a bug-fix of my own. import android.content.Context; import android.graphics.Paint; import android.util.AttributeSet; import android.util.TypedValue; import android.widget.TextView; public … Read more