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

RES-1973 Older browsers not rendering stats correctly #731

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 23 additions & 7 deletions resources/js/components/StatsShare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,14 @@ export default {
let text = ''

// Use the line height of this as our standard for moving down the image.
let lineHeight = ctx.measureText(
this.$lang.get('partials.share_modal_weve_saved') + str + this.$lang.get('partials.share_modal_of_co2')
).emHeightAscent + ctx.measureText(str).emHeightDescent + MARG * 2
//
// Older browsers don't support emHeight*
let measure1 = ctx.measureText(this.$lang.get('partials.share_modal_weve_saved') + str + this.$lang.get('partials.share_modal_of_co2'))
let measure2 = ctx.measureText(str)
let asc = measure1.emHeightAscent ? 'emHeightAscent' : 'actualBoundingBoxAscent'
let desc = measure1.emHeightDescent ? 'emHeightDescent' : 'actualBoundingBoxDescent'
let lineHeight = measure1[asc] + measure2[desc] + MARG * 2
console.log('Line height', lineHeight)

let wholeline

Expand Down Expand Up @@ -465,9 +470,12 @@ export default {

ctx.font = "bold " + this.smallerFontSize + "px Asap, sans-serif"

lineHeight = ctx.measureText(
this.$lang.get('partials.share_modal_weve_saved') + str + this.$lang.get('partials.share_modal_of_co2')
).emHeightAscent + ctx.measureText(str).emHeightDescent + MARG * 2
// Older browsers don't support emHeight*
measure1 = ctx.measureText(this.$lang.get('partials.share_modal_weve_saved') + str + this.$lang.get('partials.share_modal_of_co2'))
measure2 = ctx.measureText(str)
asc = measure1.emHeightAscent ? 'emHeightAscent' : 'actualBoundingBoxAscent'
desc = measure1.emHeightDescent ? 'emHeightDescent' : 'actualBoundingBoxDescent'
lineHeight = measure1[asc] + measure2[desc] + MARG * 2

if (RANGES[ix][2] != 'Hectare') {
if (this.portrait) {
Expand Down Expand Up @@ -533,6 +541,7 @@ export default {
// Write the text.
ctx.fillStyle = colour || 'black'
ctx.strokeStyle = colour || 'black'
console.log('Fill', str, x, y)
ctx.fillText(str, x, y)

// Return where we're up to.
Expand All @@ -556,7 +565,14 @@ export default {
},
fillWhiteBlackBox(str, x, y) {
const ctx = this.ctx
ctx.roundRect(x, y - ctx.measureText(str).emHeightAscent - MARG, ctx.measureText(str).width + MARG * 2, ctx.measureText(str).emHeightAscent + ctx.measureText(str).emHeightDescent + MARG * 2, RADIUS)

if (ctx.roundRect) {
ctx.roundRect(x, y - ctx.measureText(str).emHeightAscent - MARG, ctx.measureText(str).width + MARG * 2, ctx.measureText(str).emHeightAscent + ctx.measureText(str).emHeightDescent + MARG * 2, RADIUS)
} else {
// Older browsers.
ctx.rect(x, y - ctx.measureText(str).emHeightAscent - MARG, ctx.measureText(str).width + MARG * 2, ctx.measureText(str).emHeightAscent + ctx.measureText(str).emHeightDescent + MARG * 2)
}

ctx.fill()

// Looks like we need a beginPath() to prevent future calls to roundRect working on the same rectangle and
Expand Down
Loading