几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量  


返回   几何尺寸与公差论坛------致力于产品几何量公差标准GD&T (GDT:ASME)|New GPS(ISO)研究/CAD设计/CAM加工/CMM测量 » 仿射空间:CAX软件开发(三)二次开发与程序设计 » CAD二次开发 » AutoCAD二次开发 » DirectDWG
用户名
密码
注册 帮助 会员 日历 银行 搜索 今日新帖 标记论坛为已读


回复
 
主题工具 搜索本主题 显示模式
旧 2009-05-05, 10:05 AM   #1
yang686526
高级会员
 
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
yang686526 向着好的方向发展
默认 【转帖】exhostappservicesttffilenamebydescriptor problems

exhostappservices::ttffilenamebydescriptor problems
exhostappservices::ttffilenamebydescriptor problems
question is related to win32 platform only. sample code refered to are from the 2.0.3 release.
the current implementation in the examples of ttffilenamebydescriptor cause access violations now and then when it fails to find a font.
so i'm currently in the progress of rewriting this for our application.
but while reading another post i came across a reply stating that:
"for ttf fonts on windows dd uses windows api to access installed fonts. and does not access .ttf files directly."
ttffilenamebydescriptor() is used to get file name to access ttf font via freetype library and in file dependence manager. freetype library is used on non windows platform basically but may be use on windows also (for example: debug). so we need file name (freetype) and descriptor(windows api) for initialize font manager.
we don't need to call this function for shx font because drawing contents file name.
best regards,
sergey z.
i'm also having occasional crashes caused because the font enumeration code isn't checking for success before using the result. is there any chance this could be fixed for the next release? we copy this class directly from the installation into our codebase when we upgrade dwgdirect so it would be nice if we didn't have to do the change ourselves everytime. thanks.
can someone please explain how this fix was included in 2.2:
4083 - memory overwrite may occur in exhostappservices::ttffilenamebydescriptor when font is not found.
i have found that this method causes an exception even on 2.2. i thought the sample code may have an updated method but it appears to be exactly the same as what i have.
if i comment out this method and just return false the exception goes away.
thanks for any additional info you can provide.
chad
the fix certainly got into 2.2. make sure you did not mix old and new versions. in 2.2 the code looks like this:
code:
bool exhostappservices::ttffilenamebydescriptor(const odttfdescriptor& descr, odstring& filename)
{
#if defined(_msc_ver) && defined(_win32) && !defined(_win32_wce)
odstring snonexactmatched;
odstring sfacename = descr.typeface();
osversioninfo os;
os.dwosversioninfosize=sizeof(osversioninfo);
::getversionex(&os);
odstring sname;
sname.format(dd_t("software\\microsoft\\windows%ls\\currentversion\\"),
(os.dwplatformid & ver_platform_win32_nt)!=0 ? dd_t(" nt") : dd_t(""));
long nres;
hkey hfontsubstitutes;

dword ndatasize;
nres = ::regopenkeyex(hkey_local_machine, sname + dd_t("fontsubstitutes\\"), 0, key_read, &hfontsubstitutes);
if (hfontsubstitutes)
{
odstring svaluename;
svaluename.format(dd_t("%ls,%d"), descr.typeface().c_str(), descr.charset());
nres = ::regqueryvalueex(hfontsubstitutes, svaluename, null, null, null, &ndatasize);
if(nres == error_success)
{
char* lpdata = new char[ndatasize];
nres = ::regqueryvalueex(hfontsubstitutes, svaluename, null, null, (lpbyte)lpdata, &ndatasize);
sfacename = (lpctstr)lpdata;
delete [] lpdata;
int n = sfacename.find(',');
if(n>0)
{
sfacename = sfacename.left(n);
}
}
nres = ::regclosekey(hfontsubstitutes);
}
hkey hfonts;
::regopenkeyex(hkey_local_machine, sname + dd_t("fonts\\"), 0, key_read, &hfonts);
if (hfonts)
{
dword nindex = 0;
dword nvalnamesize = 20;
ndatasize = odmax(filename.getalloclength(), 20);
int n_bt = sfacename.replace(dd_t(" bt"), dd_t(" "));
for(;
{
odstring svaluename;
do
{
tchar* lpvalname = new tchar[nvalnamesize];
lpbyte lpdata = new byte[ndatasize];
nres = ::regenumvalue(hfonts, nindex, lpvalname, &nvalnamesize, null, null, lpdata, &ndatasize);
if (nres == error_more_data)
{
nvalnamesize += 20;
}
else if (nres == error_success)
{
svaluename = lpvalname;
filename = (lpctstr)lpdata;
}
else
{
svaluename.empty();
filename.empty();
}
delete [] lpvalname;
delete [] lpdata;
}
while (nres == error_more_data);
if (nres == error_success)
{
++nindex;
nvalnamesize = svaluename.getalloclength();
ndatasize = filename.getalloclength();
if(svaluename.replace(dd_t("(truetype)"), dd_t(""))) // is truetype font?
{
if(svaluename.replace(dd_t(" bt"), dd_t(""))==n_bt)
{
bool bbold = false;
if(n_bt)
{
svaluename.replace(dd_t(" extra bold "), dd_t(" xbd "));
}
else
{
if(svaluename.find(dd_t(" extra bold "))==-1)
bbold = (svaluename.replace(dd_t(" bold "), dd_t(" "))!=0);
}

bool bitalic = (svaluename.replace(dd_t(" italic "), dd_t(" "))!=0);
svaluename.remove(' ');
sfacename.remove(' ');
if(svaluename==sfacename)
{
snonexactmatched = filename;
if(descr.isbold()==bbold && descr.isitalic()==bitalic)
break;
}
if ( svaluename.find((sfacename+l"&").c_str()) != -1 ||
svaluename.find((l"&"+sfacename).c_str()) != -1 )
{
snonexactmatched = filename;
break;
}
}
}
}
else
{
filename = snonexactmatched;
break;
}
}
::regclosekey(hfonts);
}
return (!filename.isempty());
#else
return false;
#endif
}
where do you get the error?
vladimir
thank you very much. after a closer inspection of the code i found where there were a couple of changes.
before making this change, i would get unexplainable exceptions without a clear callstack after loading a specific set of multiple dwg files consecutively. i never saw it crash in this method.
-chad
yang686526离线中   回复时引用此帖
GDT自动化论坛(仅游客可见)
回复


主题工具 搜索本主题
搜索本主题:

高级搜索
显示模式

发帖规则
不可以发表新主题
不可以回复主题
不可以上传附件
不可以编辑您的帖子

vB 代码开启
[IMG]代码开启
HTML代码关闭



所有的时间均为北京时间。 现在的时间是 11:42 AM.


于2004年创办,几何尺寸与公差论坛"致力于产品几何量公差标准GD&T | GPS研究/CAD设计/CAM加工/CMM测量"。免责声明:论坛严禁发布色情反动言论及有关违反国家法律法规内容!情节严重者提供其IP,并配合相关部门进行严厉查处,若內容有涉及侵权,请立即联系我们QQ:44671734。注:此论坛须管理员验证方可发帖。
沪ICP备06057009号-2
更多