SolarTheCenter / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

[Feature Request] Font Size should be in sp, not in px #360

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Set any text size in a ldpi environment.
2. All works fine, you're pleased with rendering.
3. switch to a higher resolution device, let's say hdpi.
4. See how the font is small now, nearly unreadable.

What is the expected output? What do you see instead?
At every resolution, the font rendering should be PROPORTIONAL.

Please provide a source code snippet that we can use to replicate the issue.
--

What version of the product binary library are you using?
1.1.0

Please provide any additional information below.
It's a common (and best) practice to use sp as a measure unit for fonts. This 
grants that every device will scale the text sizes accordingly to its own 
resolution.

Thank you.

Original issue reported on code.google.com by luca.cri...@gmail.com on 5 Oct 2013 at 7:43

GoogleCodeExporter commented 9 years ago
Moreover, the same concept should be applied (in dp, this time, not in sp) to 
Paddings, Margins, etc...

Original comment by luca.cri...@gmail.com on 5 Oct 2013 at 11:22

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I have dimensions in dimen.xml and convert them to pixels when I am configuring 
the renderer.
Still, there are lots of "magic numbers" in the code, specially related to the 
legends. I am trying to fix some directly in the code, but so far I can't make 
them look nice in different resolutions...

Original comment by tral...@gmail.com on 26 Nov 2013 at 4:51

GoogleCodeExporter commented 9 years ago
I do assign different pixel values (defined empirically) in an initializer 
routine.
The result is vary from device to device...
I should build a better set of "magic numbers"

Original comment by luca.cri...@gmail.com on 28 Nov 2013 at 10:16

GoogleCodeExporter commented 9 years ago
Hi!

There is no possible set of "magic numbers" that will work nice on every 
device. 
I know because I am testing in 2 handhelds, one with 320x480 resolution and the 
other with 1920x1080 (Full HD) :).
The only way is to use pixel independent numbers.

I changed the code a bit and got pretty good results! 
I set the legend text size (as with other vars) in a pixel independent way 
(converted from SP). Like this: 
http://stackoverflow.com/questions/14067642/label-text-size-according-to-the-scr
een-size-in-a-chart-engine-pie-chart-in-andr/20242407#20242407

Then I made SHAPE_WIDTH = (int)renderer.getLegendTextSize() in LineChart and 
BarChart.
In drawLegend of AbstractChart, float size = renderer.getLegendTextSize();
Other paddings and sizes were also converted to fractions of 
getLegendTextSize(), in a semi-empirically way.

I know this is also a bit of a hack. I can show you my code or help implement a 
proper way to do this, perhaps adding another configurable parameter to the 
Renderer.

Original comment by tral...@gmail.com on 28 Nov 2013 at 10:41

GoogleCodeExporter commented 9 years ago
Hello!

So, you were talking of aChartEngine source (better solution).

I was talking of my own app, using some hardcoded pixel values I tested on 4 
devices
(ldpi, mdpi, hdpi and xhdpi - emulator refuses to start a xxhdpi avd and I 
don't own a physical one).

Your approach is without doubt better than mine.
But now I'm in a hurry, so I have to accelerate my developing a bit...

Original comment by luca.cri...@gmail.com on 28 Nov 2013 at 10:53

GoogleCodeExporter commented 9 years ago
Oh, sorry, I lost the scope of this thread for a bit.

I was able to make almost everything work perfectly across resolutions without 
changing the achartengine code, with the technique described in the 
stackoverflow link.

I just had to hack into the achartengine code to fix the legends.

Original comment by tral...@gmail.com on 28 Nov 2013 at 11:04

GoogleCodeExporter commented 9 years ago
;) I did my hacks too.

One of which was to strip down the library down to a mere 38 KB.
Just to have Line and Time Charts.
No zoom, no pan, no buttons, ...

And I fixed "different color for text values" (different from wave color).
And I fixed "isolated points not showing" (now they do).

;D

Original comment by luca.cri...@gmail.com on 28 Nov 2013 at 11:14

GoogleCodeExporter commented 9 years ago
Well, I used a technique similar to answer #7 in the link you posted.
But I thing you are referring to a technique like answer #0.

Though, I found that answer #5 is much interesting... 

DisplayMetrics metrics = context.getResources().getDisplayMetrics();
float val = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 18, metrics);

I got 18 (sp) from "text size medium" in the Roboto font sizes. 

You can then use val anywhere you want to use medium sized text. For example:
renderer.setLabelsTextSize(val);

I think that this (18) and another "magic number" for margins (using 
TypedValue.COMPLEX_UNIT_DP, this time) could be a viable solution.

Original comment by luca.cri...@gmail.com on 28 Nov 2013 at 11:43