明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 458|回复: 0

CAD控件网页版文字样式

[复制链接]
发表于 2019-5-24 09:18 | 显示全部楼层 |阅读模式
本帖最后由 MxDraw 于 2019-5-24 09:19 编辑

增加文字样式

用户可以增加文字样式到数据库,并设置其字体等属性,具体实现js代码如下:
  1. function CreateText(){
  2.     //返回控件的数据库对象
  3.     var database =mxOcx.GetDatabase();
  4.     //返回数据库中的文字样式表对象
  5.     var mxtst = database.GetTextStyleTable();
  6.     //增加新的文字样式
  7.     var mxtstr = mxtst.Add("duanceng");
  8.     //设置样式
  9.     //设置文字的TrueType字体,如果文字样式设置了TrueType字体,就不会使用前面设置shx字体
  10.     //参数一为turetype字体名 参数二为是否粗写  参数三为是否斜写  参数四为windows字符集  参数五暂没使用
  11.     mxtstr.SetFont("黑体", false, false, 0, 0);
  12.     //返回文字的高度
  13.     mxtstr.textSize = 5;

  14.     //增加新的文字样式
  15.     var mxtstr = mxtst.Add("duanceng1");
  16.     //设置样式
  17.     //设置文字的TrueType字体,如果文字样式设置了TrueType字体,就不会使用前面设置shx字体
  18.     //参数一为turetype字体名 参数二为是否粗写  参数三为是否斜写  参数四为windows字符集  参数五暂没使用
  19.     mxtstr.SetFont("黑体", false, false, 0, 0);
  20.     //返回文字的高度
  21.     mxtstr.textSize = 9;
  22.     //返回数据库中的文字样式表对象
  23.     //设置为当前文字样式
  24.     database.CurrentlyTextStyle = "duanceng";
  25. }
复制代码

得到文字样式名

用户可以得到所有文字样式名,具体实现js代码如下:
  1. function GetAllText() {
  2.     var database = mxOcx.GetDatabase();
  3.     // 得到所有图层名
  4.     var sRet = null;
  5.     //返回数据库中的文字样式表对象
  6.     var spTextStyleTable = database.GetTextStyleTable();
  7.     //创建一个遍历层表中所有图层的遍历器
  8.     var spIter = spTextStyleTable.NewIterator();
  9.     //移动当前遍历器位置
  10.     for(;!spIter.Done();spIter.Step(true,true))
  11.     {
  12.         //返回遍历器当前位置的记录
  13.         var spTextStyleRec = spIter.GetRecord();
  14.         //符号表记录名属性
  15.         var sName = spTextStyleRec.Name;
  16.         // 0零层不参加比较
  17.         if(sName != "0")
  18.         {
  19.             if(sRet == null)
  20.                 sRet = sName;
  21.             else
  22.             {
  23.                 sRet = sRet +","+sName;
  24.             }
  25.         }
  26.     }
  27.     alert(sRet);
  28. }
复制代码

删除文字样式

用户可以删除某个文字样式,具体实现js代码如下:
  1. function DelText() {
  2.     var winWidth = 440;
  3.     var winHeight = 140;
  4.     var winLeft = (screen.width - winWidth) / 2;
  5.     var winTop = (screen.height - winHeight) / 2 - 20;
  6.     var str = 'dialogHeight:' + winHeight + 'px;dialogWidth:' + winWidth + 'px;dialogTop:' + winTop + 'px;dialogLeft:' + winLeft + 'px;resizable:yes;center:yes;status:no;'
  7.     var rt = window.showModalDialog("Gettext.htm?tmp=" + Math.random(), "输入图层名", str);
  8.     var txt;
  9.     if (typeof (rt) == "undefined") {
  10.         return;
  11.     } else {
  12.         var arr = rt.split(",");
  13.         txt = arr[0];
  14.     }
  15.     var database = mxOcx.GetDatabase();
  16.     //返回数据库中的文字样式表表对象
  17.     var TextStyleTable = database.GetTextStyleTable();
  18.     //得到层表中的文字样式表对象
  19.     var TextStyleRec = TextStyleTable.GetAt(txt, false);
  20.     if (TextStyleRec == null)
  21.         return;
  22.     //删除对象
  23.     TextStyleRec.Erase();
  24.     alert("成功删除文字样式");
  25. }
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-19 20:37 , Processed in 0.182577 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表