Merge pull request #15232 from calixteman/15229
Fix text selection with hdpi screens (#15229)
This commit is contained in:
		
						commit
						0c5afe9269
					
				@ -132,12 +132,14 @@ function appendText(task, geom, styles, ctx) {
 | 
				
			|||||||
        paddingRight: 0,
 | 
					        paddingRight: 0,
 | 
				
			||||||
        paddingTop: 0,
 | 
					        paddingTop: 0,
 | 
				
			||||||
        scale: 1,
 | 
					        scale: 1,
 | 
				
			||||||
 | 
					        fontSize: 0,
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    : {
 | 
					    : {
 | 
				
			||||||
        angle: 0,
 | 
					        angle: 0,
 | 
				
			||||||
        canvasWidth: 0,
 | 
					        canvasWidth: 0,
 | 
				
			||||||
        hasText: geom.str !== "",
 | 
					        hasText: geom.str !== "",
 | 
				
			||||||
        hasEOL: geom.hasEOL,
 | 
					        hasEOL: geom.hasEOL,
 | 
				
			||||||
 | 
					        fontSize: 0,
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  task._textDivs.push(textDiv);
 | 
					  task._textDivs.push(textDiv);
 | 
				
			||||||
@ -166,6 +168,8 @@ function appendText(task, geom, styles, ctx) {
 | 
				
			|||||||
  textDiv.style.fontSize = `${fontHeight}px`;
 | 
					  textDiv.style.fontSize = `${fontHeight}px`;
 | 
				
			||||||
  textDiv.style.fontFamily = style.fontFamily;
 | 
					  textDiv.style.fontFamily = style.fontFamily;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  textDivProperties.fontSize = fontHeight;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Keeps screen readers from pausing on every new text span.
 | 
					  // Keeps screen readers from pausing on every new text span.
 | 
				
			||||||
  textDiv.setAttribute("role", "presentation");
 | 
					  textDiv.setAttribute("role", "presentation");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -595,6 +599,7 @@ class TextLayerRenderTask {
 | 
				
			|||||||
    this._capability = createPromiseCapability();
 | 
					    this._capability = createPromiseCapability();
 | 
				
			||||||
    this._renderTimer = null;
 | 
					    this._renderTimer = null;
 | 
				
			||||||
    this._bounds = [];
 | 
					    this._bounds = [];
 | 
				
			||||||
 | 
					    this._devicePixelRatio = globalThis.devicePixelRatio || 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Always clean-up the temporary canvas once rendering is no longer pending.
 | 
					    // Always clean-up the temporary canvas once rendering is no longer pending.
 | 
				
			||||||
    this._capability.promise
 | 
					    this._capability.promise
 | 
				
			||||||
@ -680,14 +685,17 @@ class TextLayerRenderTask {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    let transform = "";
 | 
					    let transform = "";
 | 
				
			||||||
    if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
 | 
					    if (textDivProperties.canvasWidth !== 0 && textDivProperties.hasText) {
 | 
				
			||||||
      const { fontSize, fontFamily } = textDiv.style;
 | 
					      const { fontFamily } = textDiv.style;
 | 
				
			||||||
 | 
					      const { fontSize } = textDivProperties;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Only build font string and set to context if different from last.
 | 
					      // Only build font string and set to context if different from last.
 | 
				
			||||||
      if (
 | 
					      if (
 | 
				
			||||||
        fontSize !== this._layoutTextLastFontSize ||
 | 
					        fontSize !== this._layoutTextLastFontSize ||
 | 
				
			||||||
        fontFamily !== this._layoutTextLastFontFamily
 | 
					        fontFamily !== this._layoutTextLastFontFamily
 | 
				
			||||||
      ) {
 | 
					      ) {
 | 
				
			||||||
        this._layoutTextCtx.font = `${fontSize} ${fontFamily}`;
 | 
					        this._layoutTextCtx.font = `${
 | 
				
			||||||
 | 
					          fontSize * this._devicePixelRatio
 | 
				
			||||||
 | 
					        }px ${fontFamily}`;
 | 
				
			||||||
        this._layoutTextLastFontSize = fontSize;
 | 
					        this._layoutTextLastFontSize = fontSize;
 | 
				
			||||||
        this._layoutTextLastFontFamily = fontFamily;
 | 
					        this._layoutTextLastFontFamily = fontFamily;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
@ -695,7 +703,8 @@ class TextLayerRenderTask {
 | 
				
			|||||||
      const { width } = this._layoutTextCtx.measureText(textDiv.textContent);
 | 
					      const { width } = this._layoutTextCtx.measureText(textDiv.textContent);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if (width > 0) {
 | 
					      if (width > 0) {
 | 
				
			||||||
        const scale = textDivProperties.canvasWidth / width;
 | 
					        const scale =
 | 
				
			||||||
 | 
					          (this._devicePixelRatio * textDivProperties.canvasWidth) / width;
 | 
				
			||||||
        if (this._enhanceTextSelection) {
 | 
					        if (this._enhanceTextSelection) {
 | 
				
			||||||
          textDivProperties.scale = scale;
 | 
					          textDivProperties.scale = scale;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user