|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:4 \9 V ^ T. }) d: b& o! s
! o8 u1 Y7 v' c, B: Evoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
8 P+ M! t0 U* w* A{
. ~* N6 b4 n$ i: t. j' l4 P if (m_pTextBuilder == NULL): n# r0 e: {/ S: q6 Y6 F/ `
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);7 f/ o8 W. G8 Q$ s @* w* y% ?9 P
int i = 0;1 I5 H0 L5 J9 E, l
2 S( C1 K7 @/ o1 j" e( | m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
w7 P- L* A# F! ~ m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
+ Q( @; {6 s5 P NXOpen::Features::TextBuilder::ScriptOptions characterSet;
# B T* i0 f5 v$ n2 B7 N if (fontType[1] >= 'A'&&fontType[1] <= 'z')
0 h2 t/ G" z" m; K) _ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
8 A% Q+ }- e6 Q else! E. e, E2 @" a r$ e3 C
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
. ~/ u" O+ }: l# D i = 0;
9 k& B+ V' i5 s while (1)
6 A0 }$ R. w, ^ {. x' w6 z1 l; j. b
if (fontContent == 0) break;
# ?5 b1 h& T+ r6 S* g0 e0 @ if (fontContent & 0x80)/ a8 x4 ?( S) a" \1 K1 t
if (fontContent[i + 1] & 0x80)
+ `" K) M$ w4 p* p6 `" E. G. G. @9 { if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
; _& X. Z, Z) h: U7 N$ Q {
- {- k& j1 M/ h) n, h, k$ d4 W uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);6 _: ?! V- k- A/ p+ B! c# M
break;
K4 Z7 x& Y, \! I }
! h9 G8 i u2 z! \' l& s i++;
4 v3 T( z( m$ k7 D$ q2 ] }
9 V& q+ u7 {* t' Q m_pTextBuilder->SetTextString(fontContent);' T3 Z6 a# P( ^
m_pTextBuilder->SelectFont(fontType, characterSet);( n) P- z! `9 m7 h0 ]! P
m_pTextBuilder->SetCanUseKerningSpaces(true);
" l2 `' a& I7 E m_pTextBuilder->SetCanReverseIntersectionCurve(true);$ S0 o1 i2 X7 d }0 ^
" T; s. S7 ?% T9 a6 p# b NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),( r5 L4 W& _2 r3 A0 r: }: {
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),8 t9 B6 B0 z! @1 O4 v7 P
SmartObject::UpdateOption::UpdateOptionWithinModeling);+ X# _1 A1 Y" d& @$ X" c
m_pTextBuilder->SetOrientationVector(orientationVector);9 C- j3 c% E& M; q% u& n. p
) s6 x Y2 S6 w' {; x I F% R
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
; S5 z& g1 I- D; i) Y* i m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);8 {; N, M7 Q! J* ~$ X
" J C B. E' i
i = strlen(fontContent);
a; s& c) u. x! X: Y char buf[256] = { 0 };3 ^% X Z, o) w0 I- b
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
$ X( a% C* ^4 w m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
) l$ ?' S5 B0 |. Y sprintf(buf, "%f", 10 * (wScale / 50.0));
" i! P5 t: u. n' Y m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);$ `% e" c6 x! M s; a
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
9 Z0 H1 _: Q: R; P* ?7 d# Z0 Q5 l+ _
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);% O) N3 Q0 d/ o$ @* B O0 r
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
5 G) v+ c/ [4 x2 m7 ]& j* T m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
/ y" X: G8 W# C1 P4 B( h' B3 d m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");& o) t; D# @8 W2 J0 {# Q# P
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");( H- Y8 y% |9 f3 M: t8 j
" H. F6 G2 m1 R4 G0 R std::vector<NXOpen::Face *> boundaryFaces2(0);
# o) N) M1 D: k9 S: m& `' r/ E/ q NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
: n. h* _" e$ g; l std::vector<NXOpen::SelectionIntentRule *> rules2(1);7 q' z- R5 R* f& r( B C
rules2[0] = faceTangentRule2;, b% I% ]* I4 R
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
1 t5 }3 h. w; Z. U( |: D% @) c1 k2 r( d9 v& ~
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);' L* r& W% T$ M% [1 V5 {
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
: X9 r# i6 U2 q% q1 s CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
+ T# T5 G8 r5 L- ^, G NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
# Y. p" H. K% ^. w2 U NXOpen::Curve *nullNXOpen_Curve(NULL);7 A$ q; h6 v( c3 @- e
std::vector<NXOpen::SelectionIntentRule *> rules(1);
9 D) k A0 {$ C( f, y( n rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
" j$ M* ^# W s% B m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
: Q# i% X. C0 [" q F; u6 X5 c NXOpen::NXObject *nullNXOpen_NXObject(NULL);# {4 r7 C- B# a' o% u" Q7 B
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
1 S1 Q- r% X# J! N$ ?- i: R m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
+ }7 L2 |0 y& `" O4 g0 z NXOpen::Section::ModeCreate, false);
4 N+ r. O: |/ Y3 y0 k( d; u/ G* q# a8 A8 ], O) k- E% n5 q4 a( L; }
if (bools)
+ l/ X/ C. r8 F8 _2 x2 o. W {
* {7 T& c9 _. Z; T4 i4 k " z4 e8 n4 E2 K& x" m! b
if (m_pTextBuilder->Validate())& O$ ~! g" ~5 J4 O1 t
{$ G4 |: b0 r% A4 [
m_pTextObject = m_pTextBuilder->Commit();
. Q' x' r$ d2 N5 h) D m_pTextBuilder->Destroy();% o/ \4 u8 C3 ~- O- D/ A/ y1 l
m_pTextBuilder = NULL;
& \) `% o* y, ~4 w; n changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
+ x: _2 K- |+ x; D# S( `& Q$ H+ o# u changeStringContent->SetSensitivity(false);
( O9 E! X& z8 a0 L0 I/ l' R0 @ changeRealScale->SetSensitivity(false);
: X, I* H* U! q; \# S }# o: Z2 G F: H* |5 a
, \, Z$ g8 z4 B! Q" I6 Z
} Q7 |1 Z% Y/ `3 O- n3 e5 Q8 a& |
else
7 u& b, _% g1 e4 A1 Q7 D {
7 {3 m ?" R y4 d/ k9 V" L: E //
" L; h- w3 g7 g u6 t% @ if (m_pTextBuilder->Validate())
$ ~5 y9 j) T" u+ y! H, C4 Y {
6 x+ G% R& F5 p( ^ m_pTextBuilder->Commit();
' L6 w2 d# U3 @ UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
, {& S4 C6 l5 M8 Y+ x: h- ^ m_pTextBuilder->Destroy();
+ `' z1 ]) v5 L Q1 e9 t m_pTextBuilder = NULL;6 G0 L! u. [# P
}
' }8 G$ Q1 U- ] }5 ` }
$ v$ b/ X( ?" r- b; ]9 C: c 0 s: L# V/ E) O/ }! R+ C
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
, Z5 c3 I3 P# v9 d, D |
|