|
分享一个绘制TEXT的函数,来源于网络。
- defun( _drawText (text, loc, layer, chHgt, chWid, chSpc, lineWid [url=home.php?mod=space&uid=31179]@key[/url] (angle 0), (just "L"), mir, (fontFile "ansifont"), parent)
- prog((p, ln, data, widFact, hgtFact, ch, x, y, pts, chPts, minY, maxY, allChPts, textLen, x0, y0, x1, rpath, objs)
- p = axlGetParam(sprintf(nil, "paramTextBlock:%d", axlDBControl('activeTextBlock)))
- when(mir, chWid = chWid * -1, chSpc = chSpc * -1)
- allChPts = list(list(" ", nil))
- p = axlDMOpenFile("VECTORFONT", fontFile, "r"); Looks for the font file in share\pcb\text
- if(p then
- while(gets(ln, p)
- data = linereadstring(ln)
- cond(
- (zerop(car(data)), t)
- (car(data) == 'Width, widFact = chWid / cadr(data))
- (car(data) == 'Height, hgtFact = chHgt / cadr(data))
- (and(index(ln, "***"), ch = caddr(parseString(ln)), index(text, ch))
- for(i, 1, car(data)
- ln = linereadstring(gets(ln, p)), x = cadr(ln) * widFact, y = caddr(ln) * hgtFact
- if(onep(car(ln)) then when(pts, chPts = append1(chPts, pts)), pts = list(x:y) else pts = append1(pts, x:y))
- minY = if(minY, min(y, minY), y), maxY = if(maxY, max(y, maxY), y)
- )
- allChPts = cons(list(ch, append1(chPts, pts)), allChPts), pts = chPts = nil
- )
- ); cond
- ); while
- else
- return("Font file not found")
- )
- axlDMClose(p)
- textLen = strlen(text) * (chWid + chSpc) - chSpc
- x0 = car(loc), y0 = cadr(loc)
- x1 = case(upperCase(substring(just, 1, 1)), ("L", x0), ("C", x0 - textLen / 2.0), ("R", x0 - textLen))
- foreach(char, parseString(text, "")
- foreach(charPts, cdr(assoc(char, allChPts))
- foreach(pathPts, charPts
- pathPts = mapcar(lambda((pt), axlGeoRotatePt(float(angle), x1 + car(pt):y0 + cadr(pt), loc)), pathPts)
- rpath = axlPathStart(pathPts, lineWid)
- objs = append(objs, car(axlDBCreatePath(rpath, layer, 'line, parent)))
- ); foreach pathPts
- ); foreach charPts
- x1 = x1 + chWid + chSpc
- ); foreach char
- return(objs)
- ))
- ; The following will draw the text "test" at -30:-30 on ETCH/TOP with a character height 4.0, width 3.0, spacing and line width 0.5 (in the default units)
- ;_drawText("test", '(-30 -30), "ETCH/TOP", 4.0, 3.0, 1.0, 0.5)
复制代码
|
|