codechrl opened a new pull request, #21874:
URL: https://github.com/apache/echarts/pull/21874

   ## Brief Information
   
   This pull request is in the type of:
   
   - [x] bug fixing
   - [ ] new feature
   - [ ] others
   
   ### What does this PR do?
   
   Makes `getTextRect` fall back to the global `textStyle` font, as text 
rendering does.
   
   ### Fixed issues
   
   #21873
   
   ## Details
   
   ### Before: What was the problem?
   
   `getTextRect` in `src/model/mixin/textStyle.ts` reads `fontStyle`, 
`fontWeight`, `fontSize` and `fontFamily` with `getShallow` only. 
`createTextStyle` falls back to the global `textStyle` for these keys. 
`getTextRect` measures a label drawn in a global font with the default font.
   
   With `grid.containLabel: true`, `legacyContainLabel.ts` measures axis labels 
with `getTextRect`. The reserved space then does not match the drawn labels. 
The `treemap` breadcrumb and the `visualMap` handle label measure text the same 
way.
   
   A local `fontSize` also drops the global `fontFamily`. With 
`axisLabel.fontSize: 10` and a global `fontFamily: 'monospace'`, `getTextRect` 
measures the label as `10px sans-serif`.
   
   ### After: How does it behave after the fixing?
   
   Each of the four font keys falls back to `ecModel.option.textStyle`, the 
source `createTextStyle` reads. zrender still builds the font string from the 
separate keys, so a `fontSize` with a unit such as `'25px'` keeps working.
   
   On Windows, the default global `fontFamily` is `'Microsoft YaHei'`. 
`getTextRect` now measures default labels in that font there, matching the 
drawn text.
   
   Added `test/ut/spec/model/textStyle.test.ts`. Two of its four cases fail 
without the change in `textStyle.ts`.
   
   ## Document Info
   
   One of the following should be checked.
   
   - [x] This PR doesn't relate to document changes
   - [ ] The document should be updated later
   - [ ] The document changes have been made in apache/echarts-doc#xxx
   
   ## Misc
   
   ### Security Checking
   
   - [ ] This PR uses security-sensitive Web APIs.
   
   ### ZRender Changes
   
   - [ ] This PR depends on ZRender changes (ecomfe/zrender#xxx).
   
   ### Related test cases or examples to use the new APIs
   
   `test/ut/spec/model/textStyle.test.ts`
   
   ### Merging options
   
   - [x] Please squash the commits into a single one when merging.
   
   ### Other information
   
   `getFont` appends `px` to any `fontSize`. It turns `'25px'` into `'25pxpx'`, 
so `getTextRect` does not reuse it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to