Skip to content

Commit

Permalink
Merge pull request #926 from jaredkhan/fix-text-jitter
Browse files Browse the repository at this point in the history
Don't round font sizes
  • Loading branch information
hyanwong authored Dec 1, 2024
2 parents 25afebc + ce64f3a commit 30dad8c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ArcTextShape extends BaseShape {
context.save();
// we need a monospaced font in order for this not to look rubbish
if (this.font_style) {
context.font = this.font_style + ' ' + ((Math.floor(this.width)).toString() + 'px courier');
context.font = this.font_style + ' ' + (this.width.toString() + 'px courier');
} else {
context.font = ((Math.floor(this.width)).toString() + 'px courier');
context.font = (this.width.toString() + 'px courier');
}
// context.fillStyle = textColor;
if (this.do_fill) {
Expand Down
24 changes: 12 additions & 12 deletions OZprivate/rawJS/OZTreeModule/src/ui/leaf_draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ function autotext(dostroke, fontStyle, fonttype, mintextsize, texttodisp, textx,
context_in.textAlign = 'left';
if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context_in.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}
var testw = context_in.measureText(texttodisp).width;
if (testw > textw)
Expand All @@ -75,11 +75,11 @@ function autotext(dostroke, fontStyle, fonttype, mintextsize, texttodisp, textx,
{
if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (dostroke)
{
Expand Down Expand Up @@ -118,11 +118,11 @@ function autotext2(dostroke, fontStyle, fonttype, mintextsize, texttodisp, textx
context_in.textAlign = 'center';
if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context_in.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}

var centerpoint = (texttodisp.length)/3;
Expand Down Expand Up @@ -169,11 +169,11 @@ function autotext2(dostroke, fontStyle, fonttype, mintextsize, texttodisp, textx

if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (dostroke)
{
Expand Down Expand Up @@ -224,11 +224,11 @@ function autotext3(
context_in.textAlign = 'center';
if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context_in.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}

var centerpoint = (texttodisp.length)/4;
Expand Down Expand Up @@ -301,11 +301,11 @@ function autotext3(

if (fontStyle)
{
context_in.font = fontStyle + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = fontStyle + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context_in.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context_in.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (dostroke)
{
Expand Down
24 changes: 12 additions & 12 deletions OZprivate/rawJS/OZTreeModule/src/util/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export function auto_text(do_stroke,font_style,text,textx,texty,textw,defpt,cont
context.textBaseline = 'middle';
context.textAlign = 'left';
if (font_style) {
context.font = font_style + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
} else {
context.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}
let testw = context.measureText(text).width;
if (testw > textw)
Expand All @@ -27,11 +27,11 @@ export function auto_text(do_stroke,font_style,text,textx,texty,textw,defpt,cont
{
if (font_style)
{
context.font = font_style + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (do_stroke)
{
Expand Down Expand Up @@ -72,11 +72,11 @@ export function auto_text2(do_stroke,font_style,text,textx,texty,textw,defpt,con
context.textAlign = 'center';
if (font_style)
{
context.font = font_style + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
}
else
{
context.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}

let centerpoint = (text.length)/3;
Expand Down Expand Up @@ -123,11 +123,11 @@ export function auto_text2(do_stroke,font_style,text,textx,texty,textw,defpt,con

if (font_style)
{
context.font = font_style + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (do_stroke)
{
Expand Down Expand Up @@ -178,11 +178,11 @@ export function auto_text3(do_stroke,font_style,text,textx,texty,textw,defpt,con
context.textAlign = 'center';
if (font_style)
{
context.font = font_style + ' ' + (Math.floor(defpt+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt+0.5)).toString() + 'px '+fonttype;
}
else
{
context.font = (Math.floor(defpt+0.5)).toString() + 'px '+ fonttype;
context.font = ((defpt+0.5)).toString() + 'px '+ fonttype;
}

let centerpoint = (text.length)/4;
Expand Down Expand Up @@ -255,11 +255,11 @@ export function auto_text3(do_stroke,font_style,text,textx,texty,textw,defpt,con

if (font_style)
{
context.font = font_style + ' ' + (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = font_style + ' ' + ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
else
{
context.font = (Math.floor(defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
context.font = ((defpt*textw/testw+0.5)).toString() + 'px '+fonttype;
}
if (do_stroke)
{
Expand Down

0 comments on commit 30dad8c

Please sign in to comment.