Skip to content

Commit 33e2ff7

Browse files
Canvas Context angle/fontsize fixes (#1457)
Small fixes after testing this PG : https://playground.babylonjs.com/#UZRZXU
1 parent 999490c commit 33e2ff7

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Polyfills/Canvas/Source/Context.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ namespace Babylon::Polyfills::Internal
257257
void Context::Rotate(const Napi::CallbackInfo& info)
258258
{
259259
const auto angle = info[0].As<Napi::Number>().FloatValue();
260-
nvgRotate(m_nvg, nvgDegToRad(angle));
260+
nvgRotate(m_nvg, angle);
261261
SetDirty();
262262
}
263263

@@ -594,10 +594,10 @@ namespace Babylon::Polyfills::Internal
594594
// Default font id, and font size values.
595595
// TODO: Determine better way of signaling to user that font specified is invalid.
596596
m_currentFontId = -1;
597-
int fontSize = 16;
597+
float fontSize{16.f};
598598

599599
// Regex to parse font styling information. For now we are only capturing font size (capture group 3) and font family name (capture group 4).
600-
static const std::regex fontStyleRegex("([[a-zA-Z]+\\s+)*((\\d+)px\\s+)?(\\w+)");
600+
static const std::regex fontStyleRegex("([[a-zA-Z]+\\s+)*((\\d+(\\.\\d+)?)px\\s+)?(\\w+)");
601601
std::smatch fontStyleMatch;
602602

603603
// Perform the actual regex_match.
@@ -606,7 +606,7 @@ namespace Babylon::Polyfills::Internal
606606
// Check if font size was specified.
607607
if (fontStyleMatch[3].matched)
608608
{
609-
fontSize = std::stoi(fontStyleMatch[3]);
609+
fontSize = std::stof(fontStyleMatch[3]);
610610
}
611611

612612
// Check if the specified font family name is valid, and if so assign the current font id.
@@ -618,7 +618,7 @@ namespace Babylon::Polyfills::Internal
618618
}
619619

620620
// Set font size on the current context.
621-
nvgFontSize(m_nvg, static_cast<float>(fontSize));
621+
nvgFontSize(m_nvg, fontSize);
622622
}
623623

624624
void Context::SetGlobalAlpha(const Napi::CallbackInfo& info, const Napi::Value& value)

0 commit comments

Comments
 (0)