How do I change font sizes in Heaps? - haxe

I'm currently coding in Haxe with Heaps and was checking on how to display text. One thing I want to do is give different font sizes to different texts. Naturally, I declared two Font instances and resized one of them. However, both texts are resized and I cannot manage to have them resize independently. How should I resize font sizes in Heaps?
class Main extends hxd.App{
override function init(){
var font : h2d.Font = hxd.res.DefaultFont.get();
var font2 : h2d.Font = hxd.res.DefaultFont.get();
font2.resizeTo(23);
var tf = new h2d.Text(font);
var tf2 = new h2d.Text(font2);
tf.text = "Hello World\nHeaps is great!";
tf.textColor = 0x00FF00;
tf.x = 100;
tf.y = 100;
tf.textAlign = Center;
tf2.text = "Hello World\nHeaps is great!";
tf2.textColor = 0x00FF00;
tf2.x = 300;
tf2.y = 300;
tf2.textAlign = Center;
s2d.addChild(tf);
s2d.addChild(tf2);
static function main(){
new Main();
}
}

The approach taken does not work because DefaultFont.get() caches the result.
You could either:
Copy the second font by doing var font2 : h2d.Font = font.clone() so that it gets its own properties.
Adjust scaleX and scaleY of Text.

Related

Text dynamic size - Animate CC HTML5canvas

I need to have a dynamic text field to control by code the size of the text and the text.
I create a dynamic text field on the Stage with the "notification" instance and the following code:
function Message () {
var text1 = new createjs.Text ("Message", "15px Arial", "# ff7700");
text.textBaseline = "alphabetic";
stage.addChild (text);
}
this.notification.text = text1;
What am I doing wrong? From already thank you very much
half resolved
var text = new createjs.Text("Mensaje", "25px Times Bold", "#ff0000");
text.x = 150;
text.y = 150;
text.color = "#0000ff";
text.textAlign = "center";
text.textBaseline = "alphabetic";
stage.addChild(text);

Get Navigation bar height in xamarin forms?

I am working on a project where i need to get the navigation bar height.I am getting the whole screen height using:
Helpers.ApplicationContext.ScreenHeight = (int)Resources.DisplayMetrics.HeightPixels / Resources.DisplayMetrics.Density;
Helpers.ApplicationContext.ScreenWidth = (int)Resources.DisplayMetrics.WidthPixels / Resources.DisplayMetrics.Density;
But I am not able to get the navigation bar height.
Can any one please suggest an idea to get the navigation bar height of my page.
Thanks in advance.
For iOS This may help you :
var navbarHeight = YourViewControllerInstance.NavigationController?.NavigationBar.Frame.Height;
For Android :
TypedArray styledAttributes = this.Theme.ObtainStyledAttributes(
new int[] { Android.Resource.Attribute.ActionBarSize });
var actionbarHeight = (int) styledAttributes.GetDimension(0, 0);
styledAttributes.recycle();
Above example gives Height in Pixel. Please find more refined sample as below which provide height in Pixel as well as DP:
TypedValue tv = new TypedValue();
int actionBarHeightInPixel = 0;
int actionBarHeightInDP = 0;
DisplayMetrics metrics = Resources.DisplayMetrics;
if (Theme.ResolveAttribute(Resource.Attribute.actionBarSize, tv, true))
{
actionBarHeightInPixel = TypedValue.ComplexToDimensionPixelSize(tv.Data, metrics);
actionBarHeightInDP = actionBarHeightInPixel / (int)metrics.Density;
}

Typo3: GIFBUILDER add distorted text on top of image

I want to open a blank catalog image and apply on top of it some skewed (distorted) text.
I have this typoscript snippet:
/**
* Catalog image
*/
lib.catalogImage = IMAGE
lib.catalogImage {
file = GIFBUILDER
file {
XY = 242,270
format = png
quality = 80
10 = IMAGE
10 {
file = EXT:theme/Resources/Public/Images/catalog_blank.jpg
}
15 = IMAGE
15 {
offset = 20,20
file = GIFBUILDER
file {
XY = 150,50
10 = TEXT
10 {
text = Datenblatt
fontSize = 12
offset = 28,110
fontColor = black
niceText = 1
}
20 = SCALE
20 {
params = -matte -virtual-pixel transparent -distort Perspective '0,0,0,0 0,90,0,90 90,0,90,25 90,90,90,65'
}
}
}
}
}
The problem is, I always get the text box white, with no text in it.
What am I doing wrong?
Blank catalog image:
Result image:
EDIT:
I've also tried adding:
niceText.after = -matte -virtual-pixel transparent -distort Perspective '0,0,0,0 0,90,0,90 90,0,90,25 90,90,90,65'
to the TEXT object, according to the docs (https://docs.typo3.org/typo3cms/TyposcriptReference/Gifbuilder/ObjectNames/Index.html), but it doesn't seem to be considered at all.
The result is this:
It looks like niceText doesn't get along with SCALE.
I removed niceText and the text is now displayed correctly.

How to zoom all elements pof canvas with one click?

I m using fabric.js in one of my projects.
I m using zooming functionalities . I would like to know if there a simple way to zoom all the canvas (with all the elements ) in on click.
Try out this jsfiddle demonstrating zoom onclick of a button: http://jsfiddle.net/cmontgomery/H7Utw/1/. In essence you get all objects on the canvas and scale/move them by the same factor, giving the visual appearance of zoom.
var objects = canvas.getObjects();
for (var i in objects) {
var scaleX = objects[i].scaleX;
var scaleY = objects[i].scaleY;
var left = objects[i].left;
var top = objects[i].top;
var tempScaleX = scaleX * SCALE_FACTOR;
var tempScaleY = scaleY * SCALE_FACTOR;
var tempLeft = left * SCALE_FACTOR;
var tempTop = top * SCALE_FACTOR;
objects[i].scaleX = tempScaleX;
objects[i].scaleY = tempScaleY;
objects[i].left = tempLeft;
objects[i].top = tempTop;
objects[i].setCoords();
}
canvas.renderAll();
If you use zoom with fabricjs without modifying all objects use: https://github.com/wojtek-krysiak/fabricjs-viewport.
Example: http://wojtek-krysiak.github.io/fabricjs-viewport/

Best method of scaling text to fill an HTML5 canvas

I need to 'scale' text to fill an antire HTML5 canvas. It appears that the scale() method does not affect text. I've seen approximation methods with iterative loops on the measureText() method but this doesn't get me exactly what I need. Ideally I'd like to fill both horizontally and vertically without conserving the aspect ratio. Would SVG possibly be able to help with this?
My bad - Scale DOES apply to text. I've come up with a solution:
context.font = "20px 'Segoe UI'";
var metrics = context.measureText("Testing!");
var textWidth = metrics.width;
var scalex = (canvas.width / textWidth);
var scaley = (canvas.height / 23);
var ypos = (canvas.height / (scaley * 1.25));
context.scale(scalex, scaley);
context.fillText("Testing!", 0, ypos);
Scale does affect text. Try this:
var can = document.getElementById('test');
var ctx = can.getContext('2d');
ctx.fillText("test", 10, 10); // not scaled text
ctx.scale(3,3);
ctx.fillText("test", 10, 10); // scaled text
See it in action here:
http://jsfiddle.net/3zeBk/8/

Resources