|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:. r( z* J* _% w$ S; ~
( ^9 _/ b% W2 Z3 nvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
- t. F) u! E+ S) M) h9 n) d{+ _% S. `# @8 x; o8 \- M
if (m_pTextBuilder == NULL)' X% w" P; s' f s
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts); u# ^2 b+ l6 G; F7 J- Y6 r
int i = 0;
! Y$ b; n2 B; b3 N$ x+ r! T3 E* J. P7 G1 v7 z, o: f
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);3 S! H7 n$ Z0 i8 u
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);, }4 ~7 e0 k5 e' H* K
NXOpen::Features::TextBuilder::ScriptOptions characterSet;: s# T3 r( H+ I6 R" h. H; j
if (fontType[1] >= 'A'&&fontType[1] <= 'z'). P; B+ d& @! z7 [# E
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
" t# Y6 T) _0 U( u$ P else5 Y. a) h! d: e8 ~
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
/ G' g' A) N8 m. q/ Q i = 0;
& h, U) m) F) r! G) H3 y while (1)
5 v; g x7 f! I8 g2 b {, y4 V0 w( s2 R) v2 L z/ H8 D" }8 P
if (fontContent == 0) break;- V* H- c D0 u; x* m; W6 F* x5 Q
if (fontContent & 0x80)
9 i4 f7 V* y' k' K" p' d7 j1 U4 }( ? if (fontContent[i + 1] & 0x80)
! ?: U3 p# Q& w7 o) `. i if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)2 O$ ^2 y/ K9 O, u. e% p- Q
{, ^4 h3 Y. s" Z2 Q e ]1 s% v& Z! }
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
+ v k/ \) G2 J break;6 d' `* h( u, {, h4 D5 a- d6 @
}( C9 ~, X# U' f' C
i++;
9 U2 p* c% }% j) Z T9 i7 J }
: Q, S2 }" c/ e% C. _- X+ h m_pTextBuilder->SetTextString(fontContent);
) W. g. S+ _; |; n m_pTextBuilder->SelectFont(fontType, characterSet);1 C0 m, T& c% ]* X, S& p( \$ O
m_pTextBuilder->SetCanUseKerningSpaces(true);) z% C: |' l, e8 B- l7 d' N, [: M
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
8 X6 \0 i% ?% V* |8 x. f( b" l9 q: _
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
; E2 L$ `+ g+ |3 j' d: I+ B Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
( w( Y4 l9 V+ ~+ B7 b8 \ SmartObject::UpdateOption::UpdateOptionWithinModeling);& U; o6 t( R, u8 n! n+ D& o
m_pTextBuilder->SetOrientationVector(orientationVector);8 G0 ?7 W2 G( j5 D
. _: I3 s0 x1 ^0 F6 T m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
' |* Z+ D& d4 e m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);) v3 n/ E2 R R) U. g4 t j3 ~
) `5 J" W5 w$ k' D
i = strlen(fontContent);
! C% F: R. ~9 r- G' N char buf[256] = { 0 };( e( Y3 b7 N6 a" M8 B9 n
sprintf(buf, "%f", i * 10 * (wScale / 50.0));# x7 X+ T. U' m/ [3 O
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
& O8 z0 i5 F/ e* O, e sprintf(buf, "%f", 10 * (wScale / 50.0));
! b! {* B' Y% `$ F m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);* }7 C* P8 j6 X) D, D7 f" g6 u2 H
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
, m7 C+ ^4 Q) q, z# L0 W3 a' K+ }! u
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);+ c& H' Z, `" R7 u: ], ^ t
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
5 U* v- k2 p' `" t: Y7 N m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");8 `4 [' X! F, c. U/ B
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");+ u# c! R, C% s5 M+ S; q
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");& B6 k3 z5 [/ K
& j" Y: ?7 |4 x std::vector<NXOpen::Face *> boundaryFaces2(0);7 U. w& e4 M* }
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
9 E& k/ |/ |7 l6 x' U: { std::vector<NXOpen::SelectionIntentRule *> rules2(1);
2 ~. @0 T9 K6 }* O8 z6 c R rules2[0] = faceTangentRule2;
5 D5 r7 F3 a( K m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);5 {9 S- \; c- A+ w" t3 j& ~
2 Y: b: A6 A& r
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
9 }, g* h1 f4 c- P/ l( m, ^ std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);4 \7 y" o6 s, u" ?3 l" _, S
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);) }/ E; s/ W" S" O
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));; u G. k+ P) f1 Z+ v5 Q
NXOpen::Curve *nullNXOpen_Curve(NULL);, d" U8 b% c# `8 s
std::vector<NXOpen::SelectionIntentRule *> rules(1);. }- [! g: t" G+ {+ m
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
; L3 [2 v; O' T, }$ l1 K3 p m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
8 m: r) W5 g3 v% r NXOpen::NXObject *nullNXOpen_NXObject(NULL);
1 b! s, m& W: W2 @. N1 [5 X NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
9 l! ~, Y% N" V2 G/ X/ m- U m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
1 E% F& g% M4 r+ A$ N* b. V NXOpen::Section::ModeCreate, false);% e8 D1 o6 g: O+ u( f
. _! r* w7 }" F; T, Y
if (bools)
0 l6 b# V, Q+ V {
& s x# g% i+ p6 v
/ w5 u; e1 A+ ~ if (m_pTextBuilder->Validate())
' F: f, {8 |0 X* M2 K {
; W- D/ o% n0 l; @% S m_pTextObject = m_pTextBuilder->Commit();, T) X) ]2 v1 p( e) V
m_pTextBuilder->Destroy();
% d# A9 Y# f8 ]1 y7 M m_pTextBuilder = NULL;
) Z v! h Y4 p( N: T* @6 } changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);2 [" P4 `3 {' A$ V
changeStringContent->SetSensitivity(false);
/ l/ U% k# ]- [, A( r changeRealScale->SetSensitivity(false);
0 W4 X c U, k: ^. c, O }/ e- @) l: V) u3 L; K) g
! q# ?$ h2 B2 m* F
}
* e- u9 c+ V: S1 Z, e else
4 R8 c1 U, Q: h4 j9 `8 V; b {
! Q I; N, Q" g& v // ! u/ C6 U6 x& x$ ?5 O5 e
if (m_pTextBuilder->Validate()); g' ^' F: f3 O: n) c3 D9 ^' H
{' u9 M: T3 L: r' P% i* P
m_pTextBuilder->Commit();
b4 Z# c8 K2 A8 ], M UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
+ k2 A/ |- y5 Y2 g% [ m_pTextBuilder->Destroy();* b3 \6 @' N9 p4 D6 R! y( h
m_pTextBuilder = NULL;
4 D+ Z1 X) w$ \# k _ }( F9 a/ w3 r0 A& A, N1 u
} $ ?! d" X- _' U$ _0 y7 H' r) j
- ^' ?4 h4 E3 w5 y; T6 N5 v8 R0 b
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
* l8 Q, P O7 i6 `8 [' a |
|