Compare commits
2 Commits
a507f24326
...
2b54735175
Author | SHA1 | Date | |
---|---|---|---|
2b54735175 | |||
9c2151f182 |
27
service.js
27
service.js
@ -886,10 +886,11 @@ class BesService {
|
||||
* @param {Number} scale Sign scale
|
||||
* @param {Number} dpr Device pixel ratio
|
||||
*/
|
||||
setCtxFont(scale, dpr)
|
||||
{
|
||||
setCtxFont(scale, dpr) {
|
||||
const styles = window.getComputedStyle(this.canvasPanel)
|
||||
this.ctx.font = `${styles.fontStyle} ${styles.fontWeight} ${14 * scale * dpr}px ${styles.fontFamily}`
|
||||
this.ctx.font = `${styles.fontStyle} ${styles.fontWeight} ${
|
||||
14 * scale * dpr
|
||||
}px ${styles.fontFamily}`
|
||||
}
|
||||
|
||||
/**
|
||||
@ -944,10 +945,16 @@ class BesService {
|
||||
* @param {Number} x X coordinate
|
||||
* @param {Number} y Y coordinate
|
||||
* @param {DOMRect} rect Rectangle
|
||||
* @param {Number} tolerance Extra margin around the rectangle treated as "inside"
|
||||
* @returns
|
||||
*/
|
||||
static isPointInRect(x, y, rect) {
|
||||
return rect.left <= x && x < rect.right && rect.top <= y && y < rect.bottom
|
||||
static isPointInRect(x, y, rect, tolerance) {
|
||||
return (
|
||||
rect.left - tolerance <= x &&
|
||||
x < rect.right + tolerance &&
|
||||
rect.top - tolerance <= y &&
|
||||
y < rect.bottom + tolerance
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1518,7 +1525,7 @@ class BesTreeService extends BesService {
|
||||
for (let result of this.results) {
|
||||
for (let m of result.matches) {
|
||||
for (let rect of m.highlights) {
|
||||
if (BesService.isPointInRect(x, y, rect)) {
|
||||
if (BesService.isPointInRect(x, y, rect, 5)) {
|
||||
pointsInRect.push({ el, match: m })
|
||||
break
|
||||
}
|
||||
@ -2186,7 +2193,7 @@ class BesPlainTextService extends BesService {
|
||||
for (let result of this.results) {
|
||||
for (let m of result.matches) {
|
||||
for (let rect of m.highlights) {
|
||||
if (BesService.isPointInRect(x, y, rect)) {
|
||||
if (BesService.isPointInRect(x, y, rect, 5)) {
|
||||
pointsInRect.push({ el: result.range, match: m })
|
||||
break
|
||||
}
|
||||
@ -2467,11 +2474,13 @@ class BesTAService extends BesPlainTextService {
|
||||
parseFloat(styles.paddingRight) -
|
||||
parseFloat(styles.borderRightWidth)
|
||||
}px`
|
||||
textElement.style.height = `${rect.height -
|
||||
textElement.style.height = `${
|
||||
rect.height -
|
||||
parseFloat(styles.borderTopWidth) -
|
||||
parseFloat(styles.paddingTop) -
|
||||
parseFloat(styles.paddingBottom) -
|
||||
parseFloat(styles.borderBottomWidth)}px`
|
||||
parseFloat(styles.borderBottomWidth)
|
||||
}px`
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user