import type { DXFTuple } from '../../types/dxf' import common from './common' export const TYPE = 'MTEXT' interface SimpleCodes { [key: number]: string } interface MTextEntity { type: typeof TYPE string: string x?: number y?: number z?: number nominalTextHeight?: number refRectangleWidth?: number attachmentPoint?: number drawingDirection?: number styleName?: string xAxisX?: number xAxisY?: number xAxisZ?: number horizontalWidth?: number verticalHeight?: number lineSpacingStyle?: number lineSpacingFactor?: number backgroundFill?: number bgColorRGB0?: number bgColorRGB1?: number bgColorRGB2?: number bgColorRGB3?: number bgColorRGB4?: number bgColorRGB5?: number bgColorRGB6?: number bgColorRGB7?: number bgColorRGB8?: number bgColorRGB9?: number bgColorName0?: number bgColorName1?: number bgColorName2?: number bgColorName3?: number bgColorName4?: number bgColorName5?: number bgColorName6?: number bgColorName7?: number bgColorName8?: number bgColorName9?: number fillBoxStyle?: number bgFillColor?: number bgFillTransparency?: number columnType?: number columnCount?: number columnFlowReversed?: number columnAutoheight?: number columnWidth?: number columnGutter?: number columnHeights?: number [key: string]: unknown } const simpleCodes: SimpleCodes = { 10: 'x', 20: 'y', 30: 'z', 40: 'nominalTextHeight', 41: 'refRectangleWidth', 71: 'attachmentPoint', 72: 'drawingDirection', 7: 'styleName', 11: 'xAxisX', 21: 'xAxisY', 31: 'xAxisZ', 42: 'horizontalWidth', 43: 'verticalHeight', 73: 'lineSpacingStyle', 44: 'lineSpacingFactor', 90: 'backgroundFill', 420: 'bgColorRGB0', 421: 'bgColorRGB1', 422: 'bgColorRGB2', 423: 'bgColorRGB3', 424: 'bgColorRGB4', 425: 'bgColorRGB5', 426: 'bgColorRGB6', 427: 'bgColorRGB7', 428: 'bgColorRGB8', 429: 'bgColorRGB9', 430: 'bgColorName0', 431: 'bgColorName1', 432: 'bgColorName2', 433: 'bgColorName3', 434: 'bgColorName4', 435: 'bgColorName5', 436: 'bgColorName6', 437: 'bgColorName7', 438: 'bgColorName8', 439: 'bgColorName9', 45: 'fillBoxStyle', 63: 'bgFillColor', 441: 'bgFillTransparency', 75: 'columnType', 76: 'columnCount', 78: 'columnFlowReversed', 79: 'columnAutoheight', 48: 'columnWidth', 49: 'columnGutter', 50: 'columnHeights', } export const process = (tuples: DXFTuple[]): MTextEntity => { return tuples.reduce( (entity, tuple) => { const type = tuple[0] const value = tuple[1] assign(entity, type, value) return entity }, { type: TYPE, string: '', } as MTextEntity, ) } export const assign = ( entity: MTextEntity, type: number, value: string | number ): MTextEntity => { if (type in simpleCodes) { entity[simpleCodes[type]] = value } else if (type === 1 || type === 3) { entity.string += value as string } else if (type === 50) { // Rotation angle in radians entity.xAxisX = Math.cos(value as number) entity.xAxisY = Math.sin(value as number) } else { Object.assign(entity, common(type, value)) } return entity } export default { TYPE, process, assign }