高级会员
注册日期: 06-11
帖子: 14579
精华: 1
现金: 224494 标准币
资产: 234494 标准币
|
【转帖】ext Alignmen
text alignment
text alignment
hi,
i'm having problem on writing dwg file that contains text with right or centered horizontal alignment. in dxf file this problem doesn't happen.
i´m attaching two files, containig the same entities, in dxf(.txt) and dwg formats. they were generated with dwgdirect 1.10.
notice that, text positions are the same in both files, but appearence is different. what can i do to correct that? i remember there was a function in opendwg toolkit, called 'adcomputenewtextparms', to solve this problem. and in dwgdirect, is there a similar function? if exist how is it use?
i'm waiting some help.
regina
attached files
quote:
originally posted by re
what can i do to correct that? i remember there was a function in opendwg toolkit, called 'adcomputenewtextparms', to solve this problem. and in dwgdirect, is there a similar function? if exist how is it use?
you can correct that by call adjustalignment() method of oddbtext directly.
for right result using fonts can be installed on your computer.
quote:
originally posted by re
in dxf file this problem doesn't happen.
when acad loads dxf file it recalculates text entity.
quote:
you can correct that by call adjustalignment() method of oddbtext directly.
for right result using fonts can be installed on your computer.
i have already tried to call the function adjustalignment() after defining font data for text and it didn't work. i think that fonts are installed on my computer. or there is something different to do?
see the following code used to write a oddbtext entity and, please, tell me what is wrong.
code:
oddbtextptr text = oddbtext::createobject();
fillentity(text); // defines layer, color and lineweight
block->appendoddbentity(text);
// define "bottomleft" alignment position.
point3d baseposition(cadtext->baseposition());
text->setposition(tddpoint3d(baseposition).dwg());
text->setheight(cadtext->font->height);
text->setrotation(cadtext->angle);
// text content
text->settextstring(acadtext(cadtext->text).c_str());
// text alignment
switch (cadtext->vertalignment) {
case ttextvertalignment::top:
text->setverticalmode(oddb::ktexttop);
break;
case ttextvertalignment::center:
text->setverticalmode(oddb::ktextvertmid);
break;
case ttextvertalignment::bottom:
text->setverticalmode(oddb::ktextbottom);
break;
}
switch (cadtext->horizalignment) {
case ttexthorizalignment::left:
text->sethorizontalmode(oddb::ktextleft);
break;
case ttexthorizalignment::center:
text->sethorizontalmode(oddb::ktextcenter);
break;
case ttexthorizalignment::right:
text->sethorizontalmode(oddb::ktextright);
break;
}
text->setalignmentpoint(tddpoint3d(*cadtext->position).dwg());
text->settextstyle(writer->textstyleid(*cadtext->font));
text->adjustalignment(writer->database);
thank you for attention,
regina
i don't see something wrong in your code and i failed to reproduce your problem.
the next code i added in odamfcapp (in file debugcommand.h)
and called for all text entity in attached dwg file.
after that i saved dwg file and loaded its by acad. the result was correct.
code:
void extern_debugcommand(codamfcappdoc* pdoc, cdwgview* pview)
{
oddbobjectid objid = pview->getcurobjectid();
oddbobjectptr obj = objid.openobject(oddb::kforwrite);
if ( obj->iskindof(oddbtext::desc()) )
{
oddbtextptr mtext = oddbtext::cast(obj);
mtext->adjustalignment();
}
}
the next code is attempt to reproduce your situation in odamfcapp project but i have got the correct result.
code:
void extern_debugcommand(codamfcappdoc* pdoc, cdwgview* pview)
{
oddbblocktablerecordptr precord = pdoc->getmodelspaceid().safeopenobject(oddb::kforwrite);
oddbtextptr text = oddbtext::createobject();
// fillentity(text); // defines layer, color and lineweight
precord->appendoddbentity(text);
// define "bottomleft" alignment position.
// point3d baseposition(cadtext->baseposition());
text->setposition(odgepoint3d::korigin); // tddpoint3d(baseposition).dwg());
text->setheight(0.2); //cadtext->font->height);
// text->setrotation(cadtext->angle);
// text content
text->settextstring("testtext"); //acadtext(cadtext->text).c_str());
// text alignment
text->setverticalmode(oddb::ktextvertmid);
text->sethorizontalmode(oddb::ktextcenter);
text->setalignmentpoint(odgepoint3d(1.0,1.0, 0.0));// tddpoint3d(*cadtext->position).dwg());
text->settextstyle(oddbsymutil::gettextstyleid("timesnewroman", pdoc)); //writer->textstyleid(*cadtext->font));
text->adjustalignment(); //writer->database);
}
--
best regards,
sergey zaitcev
how i understand you use dwgdirect 1.10 in c++ builder 6 compiler(post about dimention). in this case dwgdirect uses freetype library for rendering true type text. freetype library need correct file name. you problem may be with font file name. in your dwg file the file name in text style is "times new roman.ttf" and typeface is "times new roman". try to set the correct font name (times.ttf) for your text style. you need call setfilename("times.ttf") method of oddbtextstylerecord.
--
best regards,
sergey zaitcev
actually, now i'm using dwgdirect 1.10 updated in c++ builder 6 compiler. and calling setfilename("times.ttf") text appearence is ok in acad!
the question is... how can i get font file name from font name? the only way is through registry?
i'm waiting an answer.
thanks,
regina.
quote:
originally posted by re
the question is... how can i get font file name from font name? the only way is through registry?
i know only this way unfortunately. you can see sample implementation in examples\exservices\exhostappservices.cpp function ttffilenamebydescriptor().
--
best regards,
sergey zaitcev
hi sergey,
i'm using function tffilenamebydescriptor() and it returns the correct font file name. but, application crashes to some font file names, with message "abnormal program termination", when adjustalignment() is called. i think the problem is in freetype library.
"txt_____.ttf" is an example of font file name that causes problem.
can you tell me if problem is in library?
thanks,
regina.
quote:
originally posted by sergey z.
you can see sample implementation in examples\exservices\exhostappservices.cpp function ttffilenamebydescriptor().
hi regina,
it is problem in dwgdirect. it will be fixed in next version.
thanks you for report.
--
best regards,
sergey zaitcev
text problems
hi sergey,
i updated library and problem reported before still hapenning. was it solved in version 1.11?
i made some tests with odwriteex, and notice that it is not necessary to call adjustalignment function to crash app. creating a text style to 'city blue print' font and creating a text using this style with horizontal alignment different of left, app returns an unexpected exception. am i doing something wrong in the code bellow?
code:
filldatabase(...)
{
... // some code
// creating a text style to 'city blue print' font
oddbobjectid cityid = addstyle(
pdb,
"city blue print",
0.0, // text size
1.0, // xscale
0.0, // prior size
0.0, // obliquing
"cityb___.ttf", // file name
false, // is shape file
"cityblueprint",// tt face name
false, // bold
false, // italic
default_charset,// charset
default_pitch | ff_dontcare // pitch and family
);
... // some code
// creating texts using 'cityid' style
addtextents(pdb, pdb->getmodelspaceid(), newlayerid, cityid );
... // some code
}
code:
void dbfiller::addtextents(oddbdatabase* pdb,
const oddbobjectid& blockid,
const oddbobjectid& layerid,
const oddbobjectid& styleid)
{
// open the block for write.
oddbblocktablerecordptr pblock = blockid.safeopenobject(oddb::kforwrite);
... // some code
// then add entity id's to group (group must remain open during this process).
// no error creating this text algined to left
addtextent(pdb, pblock, odgepoint3d(0, dy*10.0, 0) + vec, odgepoint3d(0, 0, 0) + vec,
"left text", textheight, oddb::ktextleft, oddb::ktextbase, layerid, styleid, pgroup);
// unexpected error while creating this text algined to centerfff">.
addtextent(pdb, pblock, odgepoint3d(0, 0, 0) + vec, odgepoint3d(w/2.0 - 2.0*dx, dy*8.0, 0) + vec,
"center text", textheight, oddb::ktextcenter, oddb::ktextbase, layerid, styleid, pgroup);
... // some code
}
i hope you can answer me as soon as possible.
regards,
regina.
hi regina,
it is other bug (some problem with freetype library).
it will be fixed in update 1.11. we plane to release its in a few days.
thanks you for report.
--
best regards,
sergey zaitcev
|