|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
! L6 E' G/ l9 a/ _6 W
4 p; D- { I, o9 r% |void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)" y$ i( V8 d2 c
{2 q0 E! E/ d7 d0 t" [/ X, k3 J n- V
if (m_pTextBuilder == NULL)- E/ Q/ Z: s3 g5 V, p! x! a
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
5 c- n6 ~# n7 `6 h z' @$ H int i = 0;
" S3 v1 }: Z5 I" ~4 l |, t5 s6 B- }+ F( e
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
: E/ _% o. Y" K m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);$ V. K3 j! Y% ?. ~' L9 a
NXOpen::Features::TextBuilder::ScriptOptions characterSet;- Z/ u* _6 v0 w) A o1 z
if (fontType[1] >= 'A'&&fontType[1] <= 'z')) m9 c- C0 o u: L" Y4 H' M
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
3 ?, r. _3 N. `+ k else, h3 N/ Q! y7 h2 {# a
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
* z2 Z$ Y, h, R" M4 j3 w i = 0;
+ W8 G2 a8 x: S while (1)! v% T2 D) Q4 } _9 X- ^* _' |
{
* U6 x) Z7 t- b% I. B( \4 u5 L4 U if (fontContent == 0) break;
1 e. K' ?2 m+ h2 _! a5 g8 Z t5 j if (fontContent & 0x80)4 H, S; l: h: h& g& I( d0 { |
if (fontContent[i + 1] & 0x80)
# }) u0 ^' |0 ?: ^$ R8 a, U if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)& e) h' Z) x2 o
{
( ?% U& T" r2 w) j1 N9 i2 x uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
: S0 K+ K( i; v: W. n break;6 k N- ]% T# r6 W( N
}5 M6 m1 _' U0 n! f0 Y2 G
i++;# \* m# o7 a5 e# }; {4 s
}# }1 t2 w; |/ F( n4 u
m_pTextBuilder->SetTextString(fontContent);& A7 P+ c7 \# ~- m8 u/ K0 F2 y
m_pTextBuilder->SelectFont(fontType, characterSet);* i2 Z4 J- K- J
m_pTextBuilder->SetCanUseKerningSpaces(true);
9 x% u# W& R2 }# p+ g7 T m_pTextBuilder->SetCanReverseIntersectionCurve(true);
9 M/ v4 q9 m; h# y2 A, A1 D% I2 {6 A) `+ x3 n
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),. I4 m5 G& y5 S, R0 T
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
; P" M) p& c# [ SmartObject::UpdateOption::UpdateOptionWithinModeling);
& i% Y2 K, P! e9 l4 `8 q7 a* a m_pTextBuilder->SetOrientationVector(orientationVector);
9 }6 j2 _1 h0 G0 l( e
# Z6 D# W! j$ M1 @ m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
* n% K# f* f* ?2 U4 y% @, f# H+ ]/ d m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
: L1 p) s+ l& \: K* x6 ]& r# F% g2 N4 W. p% Q- ]: d
i = strlen(fontContent);1 ?# y& y9 O( ~: Z) ?: R3 X
char buf[256] = { 0 };7 {( n* r2 K4 |/ N: Z
sprintf(buf, "%f", i * 10 * (wScale / 50.0));$ s% _) p* s! y4 F3 V$ r7 ?+ T
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
8 | l. S: y* d* Q6 | sprintf(buf, "%f", 10 * (wScale / 50.0));# t5 ?' Z% @3 d# V
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);2 S( O p( A4 O9 \* ]
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");# j3 \+ w# w3 r$ z4 [9 ~( y
) q% ]5 y, l/ V T m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
% x1 S, m. b ` d k m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");, J2 Q) y4 D9 c5 y9 P1 B
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
7 L) t$ b" M+ [, Y7 |: b m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
0 A- V2 \3 q0 e/ R; Q m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
$ L* x! E9 h9 a5 ]/ o* g) G. w" @+ h- Z* e" ]+ h9 ^7 v. K
std::vector<NXOpen::Face *> boundaryFaces2(0);
9 c) V; n% b' a$ D- C( x; I; O NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
; a& U. U0 K0 O4 N4 A# @, S- d std::vector<NXOpen::SelectionIntentRule *> rules2(1);
( ^4 [; ^; e r, h' ?8 [ rules2[0] = faceTangentRule2;. h+ h; b- [' r. F- O
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
% @9 I4 w& v2 F1 `3 O# I6 j }7 i5 l
8 \: o1 g" p5 P$ Z0 q m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);3 }+ X. B/ h8 O# U
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
) Z' G A* `6 B" M/ M0 t7 Q7 l CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
) M4 z& S) u; A NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
" w8 B7 ?5 \- | NXOpen::Curve *nullNXOpen_Curve(NULL);
9 S! V! m/ D/ p0 h" S std::vector<NXOpen::SelectionIntentRule *> rules(1);
6 {5 g- x" ~4 n4 } X# V$ ` rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);5 F% ]4 k0 q) f( T5 x: z+ C. y
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
" e9 G9 |7 I- B5 C& s5 p3 F5 a/ V, D NXOpen::NXObject *nullNXOpen_NXObject(NULL);
4 {- i4 P& Q" r0 J# ~+ @ NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
+ B& k. c8 p' a% w Y2 R: ?; ^" o m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,8 l" z1 T/ @- Z1 ^
NXOpen::Section::ModeCreate, false);
3 S8 }/ |/ Q2 G- l" U, ~
( q9 N0 ?! l3 {; k. H {. [ if (bools)
9 n( f5 ]; A& I1 J J {
9 H9 ]' n6 K3 L6 j & F2 T* [1 Y$ r. ~( |
if (m_pTextBuilder->Validate())
1 W5 ?7 x4 x( k- R6 c3 { {7 U. S [# w) l b
m_pTextObject = m_pTextBuilder->Commit();# Q0 L6 U& P( S# F% |
m_pTextBuilder->Destroy();
% z+ d8 F3 `2 q7 x- e" y( ] m_pTextBuilder = NULL;
4 x( x0 L4 m9 I# X! D) Q% U changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
1 C( X$ C! m9 x) I changeStringContent->SetSensitivity(false);1 y; [8 i& H% s2 ?$ L$ d/ i
changeRealScale->SetSensitivity(false);8 n& ^/ A# w' B3 b
}, i* I8 M2 n K% Z# t; U- Q
) Q$ c v& U% W( Q* r q& B
}
; j* U# l6 G' b8 q9 V else2 U7 z: c+ n8 C0 z7 M
{ $ B4 M3 ^2 A7 r8 t
// ' p: C1 t. |1 f) m2 }
if (m_pTextBuilder->Validate())1 ] |1 W* P J) k2 B8 U# n; n
{
F( q6 Y8 y+ o- l+ R1 y m_pTextBuilder->Commit();
6 I6 @9 z& v1 Y( {6 n) d UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
' r) F/ K- i: f5 `0 V# H m_pTextBuilder->Destroy();9 Z" R8 C5 M2 O% z* ~5 }" Z4 `+ Q7 R
m_pTextBuilder = NULL;
7 g) w( K" i0 J) _. n+ g! m }
+ B! E4 @ ]5 R } 8 w, L6 A& C: k/ z
5 I- c' |: U i C" c5 C
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
7 K4 O) w& H1 F" y% Z; U |
|