Skip to content

Commit a65a0a6

Browse files
committed
fix tests and cross compilation
1 parent 1f68155 commit a65a0a6

File tree

7 files changed

+19
-14
lines changed

7 files changed

+19
-14
lines changed

src.csharp/AlphaTab/Platform/CSharp/GdiCanvas.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,12 @@ public void FillText(string text, double x, double y)
421421
_graphics.DrawString(text, _font, _brush, new PointF((float) x, (float) y), _stringFormat);
422422
}
423423

424-
public double MeasureText(string text)
424+
public TextMetrics MeasureText(string text)
425425
{
426426
lock (MeasurementGraphics)
427427
{
428-
return MeasurementGraphics.MeasureString(text, _font, new PointF(0,0), _stringFormat).Width;
428+
var measured = MeasurementGraphics.MeasureString(text, _font, new PointF(0,0), _stringFormat);
429+
return new TextMetrics(measured.Width, measured.Height);
429430
}
430431
}
431432

src.csharp/AlphaTab/Platform/Svg/FontSizes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static void GenerateFontLookup(string family)
1313
}
1414

1515
// TODO: maybe allow fallback to GDI/Skia based on availability?
16-
FontSizeLookupTables.Set(family, new Uint8Array(new[] {8}));
16+
FontSizeLookupTables.Set(family, new FontSizeDefinition(new Uint8Array(new[] {8}), 1.2));
1717
}
1818
}
1919
}

src.kotlin/alphaTab/alphaTab/src/androidMain/kotlin/alphaTab/platform/android/AndroidCanvas.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import alphaTab.model.MusicFontSymbol
99
import alphaTab.platform.ICanvas
1010
import alphaTab.platform.TextAlign
1111
import alphaTab.platform.TextBaseline
12+
import alphaTab.platform.TextMetrics
1213
import android.content.Context
1314
import android.graphics.*
1415
import kotlin.contracts.ExperimentalContracts
@@ -283,18 +284,20 @@ internal class AndroidCanvas : ICanvas {
283284
}
284285

285286

286-
override fun measureText(text: String): Double {
287+
override fun measureText(text: String): TextMetrics {
287288
if (text.isEmpty()) {
288-
return 0.0
289+
return TextMetrics(0.0, 0.0)
289290
}
290-
var size = 0.0
291+
var width = 0.0
292+
var height = 0.0
291293

292294
textRun(typeFace, font.size, fun(paint) {
293295
val bounds = Rect()
294296
paint.getTextBounds(text, 0, text.length, bounds)
295-
size = bounds.width().toDouble()
297+
width = bounds.width().toDouble()
298+
height = bounds.height().toDouble()
296299
})
297-
return size
300+
return TextMetrics(width, height)
298301
}
299302

300303
override fun fillMusicFontSymbol(

src.kotlin/alphaTab/alphaTab/src/commonMain/kotlin/alphaTab/platform/svg/FontSizesPartials.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ internal class FontSizesPartials {
1313
}
1414

1515
// TODO: maybe allow fallback to System Rendering / Skia based on availability?
16-
FontSizes.FontSizeLookupTables.set(family, Uint8Array(ubyteArrayOf((8).toUByte())))
16+
FontSizes.FontSizeLookupTables.set(family, FontSizeDefinition(Uint8Array(ubyteArrayOf((8).toUByte())), 1.2))
1717
}
1818
}
1919
}

src/platform/svg/FontSizes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FontStyle, FontWeight } from '@src/model/Font';
22
import { Environment } from '@src/Environment';
33
import { TextMetrics } from '../ICanvas';
4+
import { WebPlatform } from '../javascript/WebPlatform';
45

56
/**
67
* Describes the sizes of a font for measuring purposes.
@@ -40,7 +41,7 @@ export class FontSizes {
4041
return;
4142
}
4243

43-
if (!Environment.isRunningInWorker) {
44+
if (!Environment.isRunningInWorker && Environment.webPlatform != WebPlatform.NodeJs) {
4445
let canvas: HTMLCanvasElement = document.createElement('canvas');
4546
let measureContext: CanvasRenderingContext2D = canvas.getContext('2d')!;
4647
const measureSize = 11;

src/rendering/glyphs/TextGlyph.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ export class TextGlyph extends EffectGlyph {
2121

2222
this._lineHeights = [];
2323
const c = this.renderer.scoreRenderer.canvas!;
24-
for (let i = 0; i < this._lines.length; i++) {
24+
for(const line of this._lines) {
2525
c.font = this.font;
26-
const h = c!.measureText(this._lines[i]).height * this.scale;
27-
this._lineHeights[i] = h;
26+
const h = c!.measureText(line).height * this.scale;
27+
this._lineHeights.push(h);
2828
this.height += h;
2929
}
3030
}

src/rendering/utils/MasterBarBounds.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class MasterBarBounds {
4747
* Gets or sets a reference to the parent {@link staffSystemBounds}.
4848
* @deprecated use staffSystemBounds
4949
*/
50-
public get StaffSystemBounds(): StaffSystemBounds | null {
50+
public get staveGroupBounds(): StaffSystemBounds | null {
5151
return this.staffSystemBounds;
5252
}
5353

0 commit comments

Comments
 (0)