-
-
Notifications
You must be signed in to change notification settings - Fork 84
Fix SVG alignment and click box #273
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,36 +28,36 @@ type IndividualHatAdjustmentSetting = Record<HatShape, IndividualHatAdjustment>; | |
|
||
const defaultShapeMeasurements: Record<HatShape, ShapeMeasurements> = { | ||
default: { | ||
hatWidthToCharacterWidthRatio: 0.507, | ||
verticalOffsetEm: -0.05, | ||
hatWidthToCharacterWidthRatio: 0.6362522386652841, | ||
verticalOffsetEm: -0.06274676909914044, | ||
}, | ||
fourPointStar: { | ||
hatWidthToCharacterWidthRatio: 0.6825, | ||
verticalOffsetEm: -0.105, | ||
hatWidthToCharacterWidthRatio: 0.8564933982032671, | ||
verticalOffsetEm: -0.13176821510819492, | ||
}, | ||
threePointStar: { | ||
hatWidthToCharacterWidthRatio: 0.9555, | ||
verticalOffsetEm: -0.055, | ||
hatWidthToCharacterWidthRatio: 1.199090757484574, | ||
verticalOffsetEm: -0.06902144600905448, | ||
}, | ||
chevron: { | ||
hatWidthToCharacterWidthRatio: 0.6825, | ||
verticalOffsetEm: -0.02, | ||
hatWidthToCharacterWidthRatio: 0.8564933982032671, | ||
verticalOffsetEm: -0.025098707639656177, | ||
}, | ||
hole: { | ||
hatWidthToCharacterWidthRatio: 0.819, | ||
verticalOffsetEm: -0.07, | ||
hatWidthToCharacterWidthRatio: 1.0277920778439205, | ||
verticalOffsetEm: -0.08784547673879664, | ||
}, | ||
frame: { | ||
hatWidthToCharacterWidthRatio: 0.61425, | ||
verticalOffsetEm: -0.02, | ||
hatWidthToCharacterWidthRatio: 0.7708440583829403, | ||
verticalOffsetEm: -0.025098707639656177, | ||
}, | ||
curve: { | ||
hatWidthToCharacterWidthRatio: 0.6825, | ||
verticalOffsetEm: -0.07, | ||
hatWidthToCharacterWidthRatio: 0.8564933982032671, | ||
verticalOffsetEm: -0.08784547673879664, | ||
}, | ||
eye: { | ||
hatWidthToCharacterWidthRatio: 0.921375, | ||
verticalOffsetEm: -0.12, | ||
hatWidthToCharacterWidthRatio: 1.1562660875744104, | ||
verticalOffsetEm: -0.15059224583793704, | ||
}, | ||
}; | ||
|
||
|
@@ -138,9 +138,6 @@ export default class Decorations { | |
const { color, shape } = this.hatStyleMap[styleName]; | ||
const { svg, svgWidthPx, svgHeightPx } = hatSvgMap[shape]; | ||
|
||
const spanWidthPx = | ||
svgWidthPx + (fontMeasurements.characterWidth - svgWidthPx) / 2; | ||
|
||
const colorSetting = vscode.workspace | ||
.getConfiguration("cursorless.colors") | ||
.get<DecorationColorSetting>(color)!; | ||
|
@@ -150,24 +147,24 @@ export default class Decorations { | |
decoration: vscode.window.createTextEditorDecorationType({ | ||
rangeBehavior: vscode.DecorationRangeBehavior.ClosedClosed, | ||
light: { | ||
after: { | ||
before: { | ||
contentIconPath: this.constructColoredSvgDataUri( | ||
svg, | ||
colorSetting.light | ||
), | ||
}, | ||
}, | ||
dark: { | ||
after: { | ||
before: { | ||
contentIconPath: this.constructColoredSvgDataUri( | ||
svg, | ||
colorSetting.dark | ||
), | ||
}, | ||
}, | ||
after: { | ||
margin: `-${svgHeightPx}px 0 0 -${spanWidthPx}px`, | ||
width: `${spanWidthPx}px`, | ||
before: { | ||
margin: `-${svgHeightPx}px -${svgWidthPx}px 0 0`, | ||
width: `${svgWidthPx}px`, | ||
height: `${svgHeightPx}px`, | ||
}, | ||
}), | ||
|
@@ -261,25 +258,24 @@ export default class Decorations { | |
) { | ||
const iconPath = join(this.extensionPath, "images", "hats", `${shape}.svg`); | ||
const rawSvg = readFileSync(iconPath, "utf8"); | ||
const { characterWidth, characterHeight } = fontMeasurements; | ||
|
||
const { originalViewBoxHeight, originalViewBoxWidth } = | ||
this.getViewBoxDimensions(rawSvg); | ||
|
||
const hatWidthPx = | ||
hatWidthToCharacterWidthRatio * fontMeasurements.characterWidth; | ||
const hatWidthPx = hatWidthToCharacterWidthRatio * characterWidth; | ||
const hatHeightPx = | ||
(originalViewBoxHeight / originalViewBoxWidth) * hatWidthPx; | ||
|
||
const svgWidthPx = Math.ceil(fontMeasurements.characterWidth); | ||
const svgHeightPx = | ||
fontMeasurements.characterHeight + hatHeightPx + hatVerticalOffset; | ||
const svgWidthPx = Math.ceil(characterWidth); | ||
const svgHeightPx = characterHeight + hatHeightPx + hatVerticalOffset; | ||
|
||
const newViewBoxWidth = | ||
((originalViewBoxWidth / hatWidthToCharacterWidthRatio) * | ||
fontMeasurements.characterWidth) / | ||
svgWidthPx; | ||
Comment on lines
-278
to
-280
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was the dumb mistake. We need to adjust from char width to svg width, not the other way around 😅 |
||
((originalViewBoxWidth / hatWidthToCharacterWidthRatio) * svgWidthPx) / | ||
characterWidth; | ||
const newViewBoxHeight = (newViewBoxWidth * svgHeightPx) / svgWidthPx; | ||
const newViewBoxX = -(newViewBoxWidth - originalViewBoxWidth) / 2; | ||
const newViewBoxX = | ||
(-(characterWidth - hatWidthPx) * (newViewBoxWidth / svgWidthPx)) / 2; | ||
Comment on lines
+277
to
+278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're left-aligned, we basically need to shift right by |
||
const newViewBoxY = 0; | ||
|
||
const newViewBoxString = `${newViewBoxX} ${newViewBoxY} ${newViewBoxWidth} ${newViewBoxHeight}`; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to play games with span width anymore because we now align to the left side of the char