Skip to content

Commit

Permalink
feat: 修改字体的渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
xxss0903 committed Oct 11, 2024
1 parent e7cdfb5 commit bd6c758
Showing 1 changed file with 50 additions and 50 deletions.
100 changes: 50 additions & 50 deletions src/liteofd/elements/TextSvg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,20 @@ export class TextSvg extends BaseSvg {

// 去掉publicres中关于字体的粗细的值的显示,只使用字体文件中的字体渲染
// 添加字体粗细
// let fontWeight = parser.findAttributeValueByKey(findedFont, AttributeKey.Weight)
// if (fontWeight) {
// this.textStyle += `font-weight: ${fontWeight};`
// }
// let fontBold = parser.findAttributeValueByKey(findedFont, AttributeKey.Bold)
// if (fontBold) {
// this.textStyle += `font-weight: bold;`
// }
// // 添加字体斜体
// let fontItalic = parser.findAttributeValueByKey(findedFont, AttributeKey.Italic)
// console.log("font italic:", fontID, findedFont, fontItalic, node)
// if (fontItalic) {
// this.textStyle += `font-style: italic;`
// }
let fontWeight = parser.findAttributeValueByKey(findedFont, AttributeKey.Weight)
if (fontWeight) {
this.textStyle += `font-weight: ${fontWeight};`
}
let fontBold = parser.findAttributeValueByKey(findedFont, AttributeKey.Bold)
if (fontBold) {
this.textStyle += `font-weight: bold;`
}
// 添加字体斜体
let fontItalic = parser.findAttributeValueByKey(findedFont, AttributeKey.Italic)
console.log("font italic:", fontID, findedFont, fontItalic, node)
if (fontItalic) {
this.textStyle += `font-style: italic;`
}
}
}
}
Expand All @@ -113,18 +113,18 @@ export class TextSvg extends BaseSvg {
this.textStyle += `font-weight: ${fontWeight};`
}
// 添加字体颜色
// this.#addFillColor(nodeData)
// // 添加stroke颜色
// this.#addStrokeColor(nodeData)
this.#addFillColor(nodeData)
// 添加stroke颜色
this.#addStrokeColor(nodeData)

// stroke宽度
// let lineWidth = parser.findAttributeValueByKey(nodeData, AttributeKey.LineWidth)
// if (lineWidth) {
// let lineWidthValue = parseFloat(lineWidth)
// this.textStyle += `stroke-width: ${convertToDpi(lineWidthValue)}px;`
// } else {
// this.textStyle += `stroke-width: 0;`
// }
let lineWidth = parser.findAttributeValueByKey(nodeData, AttributeKey.LineWidth)
if (lineWidth) {
let lineWidthValue = parseFloat(lineWidth)
this.textStyle += `stroke-width: ${convertToDpi(lineWidthValue)}px;`
} else {
this.textStyle += `stroke-width: 0;`
}


}
Expand Down Expand Up @@ -202,31 +202,31 @@ export class TextSvg extends BaseSvg {

// 字体文件中暂时去掉drawParam的渲染
#addDrawParam(nodeData: XmlData) {
// let drawParamID = parser.findAttributeValueByKey(nodeData, AttributeKey.DrawParam)
// console.log("add text draw params", drawParamID)
// if (drawParamID) {
// let drawParamNode = parser.findNodeByAttributeKeyValue(drawParamID, AttributeKey.ID, this.ofdDocument.publicRes)
// if (drawParamNode) {
// // 填充颜色
// this.#addFillColor(drawParamNode)
// // 添加线宽度和线条颜色
// this.#addStrokeColor(drawParamNode)
// console.log("textsvg drawParamNode", drawParamNode)
// // 添加字体粗细
// let fontWeight = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Weight)
// if (fontWeight) {
// this.textStyle += `font-weight: ${fontWeight};`
// }
// let fontBold = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Bold)
// if (fontBold) {
// this.textStyle += `font-weight: bold;`
// }
// // 添加字体斜体
// let fontItalic = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Italic)
// if (fontItalic) {
// this.textStyle += `font-style: italic;`
// }
// }
// }
let drawParamID = parser.findAttributeValueByKey(nodeData, AttributeKey.DrawParam)
console.log("add text draw params", drawParamID)
if (drawParamID) {
let drawParamNode = parser.findNodeByAttributeKeyValue(drawParamID, AttributeKey.ID, this.ofdDocument.publicRes)
if (drawParamNode) {
// 填充颜色
this.#addFillColor(drawParamNode)
// 添加线宽度和线条颜色
this.#addStrokeColor(drawParamNode)
console.log("textsvg drawParamNode", drawParamNode)
// 添加字体粗细
let fontWeight = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Weight)
if (fontWeight) {
this.textStyle += `font-weight: ${fontWeight};`
}
let fontBold = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Bold)
if (fontBold) {
this.textStyle += `font-weight: bold;`
}
// 添加字体斜体
let fontItalic = parser.findAttributeValueByKey(drawParamNode, AttributeKey.Italic)
if (fontItalic) {
this.textStyle += `font-style: italic;`
}
}
}
}
}

0 comments on commit bd6c758

Please sign in to comment.