Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MeasureText have only width informations #132

Open
Noeilnoeil17 opened this issue Dec 13, 2022 · 4 comments
Open

MeasureText have only width informations #132

Noeilnoeil17 opened this issue Dec 13, 2022 · 4 comments

Comments

@Noeilnoeil17
Copy link

Hi everybody,

Enjoy with this extensions, thanks a lot
When i try to use _context.MesureTextAsync, only width parameter is present, all other return 0 :-(

just tested with this simple test :

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    this._context = await this._canvasReference.CreateCanvas2DAsync();
    await this._context.SetFillStyleAsync("green");

    await this._context.FillRectAsync(10, 100, 100, 100);

    await this._context.SetFontAsync("48px serif");
    await this._context.StrokeTextAsync("Hello Blazor!!!", 10, 100);

    **var size = await this._context.MeasureTextAsync("48px serif");**

}

image

Any help is welcome,
thanks,

Noeilnoeil17

@bigDave1357
Copy link

Me too on this. Changing fonts, changing font sizes, nothing seems to change the results - all zeros except for the width and that value never changes regardless of the length of text, the font etc.

@Noeilnoeil17
Copy link
Author

Hi bigDave1357, thanks for your feedback, for now, only solution is using javascript...

function measuretextincanvas(font, text, mmToPix) {
var canvas = document.getElementById('hiddencanvas');
var ctx = canvas.getContext('2d');
ctx.font = font;
var TextWidth = ctx.measureText(text).width / mmToPix;
var TextHeight = ctx.measureText("H").actualBoundingBoxAscent / mmToPix;
return { TextWidth, TextHeight };
}

Noeilnoeil17

@bigDave1357
Copy link

Hi @Noeilnoeil17, thanks for your assistance.
I figured the same. My app needs to manipulate font sizes based on an auto-fit scenario as well as render lots of text, and I suspect I'll be better just using JS for the whole solution. Seems pointless that I have an extension for part of the work if I have to reach down into JS anyway. Kind of defeats the purpose of the extension. I'll probably get better performance working directly with JS anyway. So I'll ditch the extension.

@JaromirBedkowski
Copy link

Hi @bigDave1357 - could You help me to start with JS without this Extension ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants