OpenLaszlo font rendering not consistent for 3.x and 5.0 when using embedded fonts - openlaszlo

I am applying a custom font to a text field this is working fine in my Openlaszlo 3.3 but in the newer version(5.0) the font is getting applied and the style is also getting applied , but i see the space between the letters is more. But this is not happening in the older version.
I inspected the object in both the versions and i found that the only notable difference is the line height.
Any idea why this is happening?How to remove those spaces is it possible?
3.3 Screenshot
5.0 Screenshot

The effect you are seeing is connected to the way how Flash deals with embedded TTF fonts: Text using those fonts is completely rendered by the Flash Player. Especially the change from Flash Player 8 to 9 brought many improvement for text rendering (better anti-aliasing for embedded fonts, finally the ability to modify the letter).
The difference in rendering text you are seeing is probably caused by the better anti-aliasing in Flash Player 9 and higher. OpenLaszlo SWF9+ text and inputtext components use the setting flash.text.AntiAliasType.ADVANCED as default.
Here's a discussion in the OpenLaszlo dev mailing list mentioning the effect your are seeing:
Font rendering should be as high-quality as possible -- I don't think
anyone's going to want old-style rendering in FP9. Isn't there another way
to fix this bug?
We're not going to get complete font rendering consistency across
runtimes. It's already not consistent when using device fonts. Each
browser/player/OS variation is different, and Flash vs. DHTML is also
different.
As far I know there is not an official API for modifying that setting. I've created a small application where you can test how modifying that property affects text rendering. The top two text items use the default font for Flash Player, therefore the anti-aliasing setting does not affect the rendering. The following 4 text items all use an embedded TTF font, and you can see the difference depending on the antiAliasingType setting.
To compile the application, download the following fonts and put them into the application folder:
http://svn.openlaszlo.org/openlaszlo/trunk/laszlo-explorer/fonts/ariosob.ttf
https://github.com/w0ng/googlefontdirectory/raw/master/fonts/Amaranth-Regular.ttf
<canvas height="600">
<font name="amaranth" style="plain" src="Amaranth-Regular.ttf" />
<font name="arioso" src="ariosob.ttf" />
<class name="mytext" extends="text">
<passthrough when="$as3">
import flash.text.AntiAliasType;
</passthrough>
<attribute name="antialias" type="string" value="advanced" />
<handler name="oninit">
this.onantialias.sendEvent();
</handler>
<handler name="onantialias">
var t = this.getDisplayObject().textfield;
if ( this.antialias == 'normal' ) {
t.antiAliasType = flash.text.AntiAliasType.NORMAL;
} else {
t.antiAliasType = flash.text.AntiAliasType.ADVANCED;
}
</handler>
<method name="toogleAntialias">
if ( this.antialias == 'normal' ) this.setAttribute( 'antialias', 'advanced' );
else this.setAttribute( 'antialias', 'normal' );
</method>
</class>
<view>
<simplelayout axis="y" spacing="10" />
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="true" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="advanced"
fontsize="25">Default font (no embedded TTF)</mytext>
</view>
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="false" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="normal"
fontsize="25">Default font (no embedded TTF)</mytext>
</view>
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="true" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="advanced"
font="amaranth" fontsize="25">Amaranth Regular</mytext>
</view>
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="false" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="normal"
font="amaranth" fontsize="25">Amaranth Regular</mytext>
</view>
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="true" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="advanced"
font="arioso" fontsize="25">Amaranth Regular</mytext>
</view>
<view layout="axis:x; spacing:5">
<text valign="middle">Anti-alias advanced</text>
<checkbox value="false" y="10"
onvalue="if (parent.t) parent.t.toogleAntialias()" />
<view width="20" height="1" />
<mytext name="t"
antialias="normal"
font="arioso" fontsize="25">Amaranth Regular</mytext>
</view>
</view>
</canvas>
The results might not be consistent across all operating systems, since operating systems will use different approaches to optimizing text rendering. The above screenshot was taken on Linux.

Related

Chakra UI: Make HStack disappear with condition

I have 2 card that have same properties but has some different props, card 1 (amountBed, amountBath, area), card 2 (area).
This's my code:
<HStack spacing={"25px"}>
<HStack spacing={"12px"}>
<BedroomIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{amountBed}
</Text>
</HStack>
<HStack spacing={"12px"}>
<BathroomIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{amountBath}
</Text>
</HStack>
<HStack spacing={"12px"}>
<AreaIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{area} m<sup>2</sup>
</Text>
</HStack>
</HStack>
I want to disappear bedroom and bathroom HStack if the amountBed, amountBath equal 0 or null.
you can use logical AND operater, then this should hide bedroom and bathroom when their values are FALSY.
<HStack spacing={"25px"}>
{amountBed &&
<HStack spacing={"12px"}>
<BedroomIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{amountBed}
</Text>
</HStack>}
{amountBath && <HStack spacing={"12px"}>
<BathroomIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{amountBath}
</Text>
</HStack>}
<HStack spacing={"12px"}>
<AreaIcon />
<Text color={"black.400"} fontWeight={"bold"} fontSize={"16px"}>
{area} m<sup>2</sup>
</Text>
</HStack>
</HStack>

SVG with dynamic content as background image

I understand that the tag in SVG is mainly used for events, but I rather need it for avoiding the need to repeat code, like the following case:
<script>
var i=0,c1=0xf80,c2=0xf40,X,n=8; while(n) {
X=document.createElementNS("http://www.w3.org/2000/svg","text");
X.setAttribute("x",65-i); X.setAttribute("y",80+i); X.setAttribute("class","txt");
X.setAttribute("fill","#"+(c1.toString(16))); X.innerHTML="e";
document.rootElement.appendChild(X);
X=document.createElementNS("http://www.w3.org/2000/svg","text");
X.setAttribute("x",90-i); X.setAttribute("y",86+i); X.setAttribute("class","txt");
X.setAttribute("fill","#"+(c2.toString(16))); X.innerHTML="f";
document.rootElement.appendChild(X);
n--; i++; c1+=16; c2+=16;
}
</script>
But if I want to use the SVG as background image, the tag for some reason NOT EXECUTING, leading me to change the above code to something stupid that looks like this:
<text x="65" y="80" class="txt" fill="#f80">e</text>
<text x="90" y="86" class="txt" fill="#f40">f</text>
<text x="64" y="81" class="txt" fill="#f90">e</text>
<text x="89" y="87" class="txt" fill="#f50">f</text>
<text x="63" y="82" class="txt" fill="#fa0">e</text>
<text x="88" y="88" class="txt" fill="#f60">f</text>
<text x="62" y="83" class="txt" fill="#fb0">e</text>
<text x="87" y="89" class="txt" fill="#f70">f</text>
<text x="61" y="84" class="txt" fill="#fc0">e</text>
<text x="86" y="90" class="txt" fill="#f80">f</text>
<text x="60" y="85" class="txt" fill="#fd0">e</text>
<text x="85" y="91" class="txt" fill="#f90">f</text>
<text x="59" y="86" class="txt" fill="#fe0">e</text>
<text x="84" y="92" class="txt" fill="#fa0">f</text>
<text x="58" y="87" class="txt" fill="#ff0">e</text>
<text x="83" y="93" class="txt" fill="#fb0">f</text>
Everyone looking at the code above can see how stupid is this repeat...
Just for a quite simple task, I really doubt there is no better way of doing it.
Just imagine more complicated situation, I will need to end up with tousands of lines for nothing......
If anyone know of a way to handle repeating objects (or better doing "loop" tasks), please let me know here.
Thanks a lot in advance.:)

Can't dynamically place text over the top of polygon

I want to put text on top of my polygons. unfortunately the text goes behind the shape is there anything similar to the css z index?
here is part of the svg in my html (its a lot of code because im drawing a map so here is only a little part of it.) Although below they all have the same coords, I did originally place them over the shape using the inspector in chrome, however the shapes remained above the text.
<svg width="400" height="800" viewBox="0 0 400 800" id="svg-doc">
<rect id="central-park" class="shape" x="154" y="370"width="53" height="127" />
<a xlink:href="/zipcodes/16">
<rect id="z10024" class="shape" x="68" y="415" width="85" height="40" />
<text x="0" y="15" fill="#5df8b8">10024</text>
</a>
<a xlink:href="/zipcodes/17">
<rect id="z10023" class="shape" x="68" y="457" width="85" height="40" />
<text x="0" y="15" fill="#5df8b8">10024</text>
</a>
<a xlink:href="/zipcodes/10">
<polygon id="z10034" class="shape" points="189,156 137,122 106,121 101,129 99,155 79,155 78,105 94,79 121,67 128,82 163,61 177,62 191,80" />
<text x="0" y="15" fill="#5df8b8">10024</text>
</a>
<a xlink:href="/zipcodes/28">
<polygon id="z10040" class="shape" points="188,167 186,155 137,122 108,122 102,126 100,153 77,156 77,166" />
<text x="0" y="15" fill="#5df8b8">10024</text>
</a>
<a xlink:href="/zipcodes/29">
<polygon id="z10033" class="shape" points="189,166 187,197 187,203 81,203 77,194 78,166" />
<text x="0" y="15" fill="#5df8b8">10024</text>
</a>
According to this site: http://alignedleft.com/tutorials/d3/an-svg-primer/
The order in which elements are coded determines their depth order.
In fact, the problem seems to be that all of your text is in the same place, at (0,15) - not underneath the polygons at all?
I edited the code from the question to move the text over the polygons, it is displayed correctly...
<svg width="400" height="800" viewBox="0 0 400 800" id="svg-doc">
<rect id="central-park" class="shape" x="154" y="370"width="53" height="127" />
<a xlink:href="/zipcodes/16">
<rect id="z10024" class="shape" x="68" y="415" width="85" height="40" />
<text x="70" y="450" fill="#5df8b8">10024</text>
</a>
<a xlink:href="/zipcodes/17">
<rect id="z10023" class="shape" x="68" y="457" width="85" height="40" />
<text x="70" y="480" fill="#5df8b8">10023</text>
</a>
<a xlink:href="/zipcodes/10">
<polygon id="z10034" class="shape" points="189,156 137,122 106,121 101,129 99,155 79,155 78,105 94,79 121,67 128,82 163,61 177,62 191,80" />
<text x="90" y="110" fill="#5df8b8">10034</text>
</a>
<a xlink:href="/zipcodes/28">
<polygon id="z10040" class="shape" points="188,167 186,155 137,122 108,122 102,126 100,153 77,156 77,166" />
<text x="120" y="160" fill="#5df8b8">10040</text>
</a>
<a xlink:href="/zipcodes/29">
<polygon id="z10033" class="shape" points="189,166 187,197 187,203 81,203 77,194 78,166" />
<text x="120" y="190" fill="#5df8b8">10033</text>
</a>
</svg>

Openlaszlo dragging issue

I am try to drag a view to another view containing an html. But for some reason i am not able to drag over the html. Can any one tell me what is wrong in this code.
<canvas>
<include href="iFrame.lzx"/>
<view y="5" width="100" height="50" bgcolor="green">
<handler name="oninit">
this.bringToFront();
</handler>
<dragstate name="drg"/>
<text width="100%" bgcolor="gray" onmousedown="parent.drg.apply()" onmouseup="parent.drg.remove()">Drag me</text>
</view>
<view y="150" width="100%" height="300" bgcolor="blue" >
<html id="htdevice" src="http://www.openlaszlo.org" x="15" y="15" width="${parent.width - 30}" height="${parent.height - 30}"/>
</view>
</canvas>
you wrote mouse event listeners on text tag put your mouse on text then you can easily drag or write mouse event listeners for view tag then you can drag the view by putting your mouse pointer any where on the view(green)

How to merge multiple SVGs files on a html page?

I have been trying to merge two SVG files into single SVG file. Everywhere I found is using pageSet. Below code is to merge two SVG file to a single file.
<pageSet>
<page>
<circle cx="300" cy="150" r="90" fill="red" stroke="black"
stroke-width="4" fill-opacity="0.7" />
</page>
<page>
<circle cx="240" cy="250" r="90" fill="green" stroke="black"
stroke-width="4" fill-opacity="0.7" />
</page>
<page>
<circle cx="360" cy="250" r="90" fill="blue" stroke="black"
stroke-width="4" fill-opacity="0.7" />
</page>
</pageSet>
I tried using the above code but, nothing is displaying.
You can embed SVG files in an HTML document, one after another. For example, with either the SVG content inline:
<html><head>…</head><body>
<svg xmlns="http://www.w3.org/2000/svg"><!-- SVG Data --></svg>
<svg xmlns="http://www.w3.org/2000/svg"><!-- SVG Data --></svg>
<svg xmlns="http://www.w3.org/2000/svg"><!-- SVG Data --></svg>
<svg xmlns="http://www.w3.org/2000/svg"><!-- SVG Data --></svg>
</body></html>
…or referencing an external file:
<html><head>…</head><body>
<object type="image/svg+xml" data="file1.svg"></object>
<object type="image/svg+xml" data="file2.svg"></object>
<object type="image/svg+xml" data="file3.svg"></object>
<object type="image/svg+xml" data="file4.svg"></object>
</body></html>
You can then use CSS to control the page breaks when printing:
svg, object { page-break-before:always }

Resources