textStyle.js 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. var textContain = require("zrender/lib/contain/text");
  2. var graphicUtil = require("../../util/graphic");
  3. var PATH_COLOR = ['textStyle', 'color'];
  4. var _default = {
  5. /**
  6. * Get color property or get color from option.textStyle.color
  7. * @param {boolean} [isEmphasis]
  8. * @return {string}
  9. */
  10. getTextColor: function (isEmphasis) {
  11. var ecModel = this.ecModel;
  12. return this.getShallow('color') || (!isEmphasis && ecModel ? ecModel.get(PATH_COLOR) : null);
  13. },
  14. /**
  15. * Create font string from fontStyle, fontWeight, fontSize, fontFamily
  16. * @return {string}
  17. */
  18. getFont: function () {
  19. return graphicUtil.getFont({
  20. fontStyle: this.getShallow('fontStyle'),
  21. fontWeight: this.getShallow('fontWeight'),
  22. fontSize: this.getShallow('fontSize'),
  23. fontFamily: this.getShallow('fontFamily')
  24. }, this.ecModel);
  25. },
  26. getTextRect: function (text) {
  27. return textContain.getBoundingRect(text, this.getFont(), this.getShallow('align'), this.getShallow('verticalAlign') || this.getShallow('baseline'), this.getShallow('padding'), this.getShallow('rich'), this.getShallow('truncateText'));
  28. }
  29. };
  30. module.exports = _default;