|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:3 |1 i- i" X3 z$ q
' R& f' Q5 k H" V0 D, A+ E7 q# C! U
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
0 F3 A0 R m$ x8 t! {{( d8 d! r6 I B, {
if (m_pTextBuilder == NULL)
- v6 ~4 h+ T; Y" p m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts); w$ n. G: V1 f$ D
int i = 0;: r& ]1 _/ K8 }* |
/ `2 U* ]& Z5 ^) j0 o) b
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);& V% t0 S' p7 P. S
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);& O8 r( l. x; H* s- J/ a" y
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
0 R7 \ V- H, E- j2 L$ n4 C8 k if (fontType[1] >= 'A'&&fontType[1] <= 'z')
9 P7 x2 s1 h# V5 l& \& y0 d' ? characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;2 D+ ~& H: U5 M
else8 F" R/ g# F/ `/ b# q& M% ]
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;% S4 D4 T& \3 o2 p
i = 0;
. j0 ?6 `, \* N1 N0 o3 [" v d while (1)
6 F# o; G& R: E1 I1 ^ {
& d/ }9 ~. d. X+ Z8 B: v if (fontContent == 0) break;
1 o4 D' k$ r4 Z* K- o. { if (fontContent & 0x80)
' K/ k* ]& u6 ]' x1 J5 A, b if (fontContent[i + 1] & 0x80)
) g7 |. |9 |2 T3 }. P8 U if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
; n4 m+ [3 M( D$ H0 C; v {
' K3 }, q/ d8 _/ M6 g! B) Z: ~ uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
8 b" k# l$ v f' W break;$ C- g8 r! Q: {( [
}
- Q0 Z, k! l( p' M% l i++;- {1 r/ B8 S- t Q6 [3 W) l& V8 g
}9 v5 a T. j) K
m_pTextBuilder->SetTextString(fontContent);( a% P7 q; y) q* E ? z
m_pTextBuilder->SelectFont(fontType, characterSet);1 r# `) \" f. T3 I" j: n
m_pTextBuilder->SetCanUseKerningSpaces(true);
0 C3 C6 y4 Y8 }7 q) V% O6 y8 ~) s m_pTextBuilder->SetCanReverseIntersectionCurve(true);
; o& Z" e( [- u1 `% [2 R L
* V8 H1 w* \" i% ] NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
5 F; k- H0 Z. u8 I Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])), _" p- i1 P# m9 U) `" h
SmartObject::UpdateOption::UpdateOptionWithinModeling);& d4 N2 \8 c! T$ I* [6 R& h
m_pTextBuilder->SetOrientationVector(orientationVector);
3 I U% X) A0 n k1 g* a, }4 i
1 F: f+ v$ {. a" y0 S m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
: u; {3 w' f' G8 c m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);4 h; c. K1 j- A. m
0 Y9 A3 J5 s, k0 l/ P" ` i = strlen(fontContent);5 h7 Z- L4 W: g( _/ ]0 X
char buf[256] = { 0 };$ K) F( T0 t: w; X
sprintf(buf, "%f", i * 10 * (wScale / 50.0));# {+ h$ b* t" Q
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);% g: S% g' @0 y6 \4 L3 g" ?6 d
sprintf(buf, "%f", 10 * (wScale / 50.0));
$ |8 T" Z% E$ H8 N' ~ m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
7 T; I8 u" m3 A9 Z0 l, r5 ^# e) Y m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");: ~3 Y' \2 K5 u2 e% ~% i
( J, c* d4 B+ N m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);# B+ V3 I, v/ T3 t
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");/ r) A+ p9 S7 s
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
3 }& T0 ]# b+ Q, l0 u% `1 Q m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");5 G. g4 B9 [& U: W( Z# V
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
# y2 ]3 T& U# i9 Q
U O/ i. D/ x6 K std::vector<NXOpen::Face *> boundaryFaces2(0);
5 u# o5 k: u/ T8 |2 ^2 w4 U NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);+ U% b3 ~5 D" C* j m3 B* O+ u
std::vector<NXOpen::SelectionIntentRule *> rules2(1);6 c! e' } d9 m) R% E& C
rules2[0] = faceTangentRule2;
" q/ M7 h7 z3 @& T m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
9 x: O1 a8 k1 n$ e" Y4 d9 \ p5 ?+ X& }
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
% K' R, d) o3 V1 \1 e6 M ~ std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
& V/ G5 C; r3 \0 C, ]! X CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);' j" e8 Q3 b' P) p6 F/ }: V7 ?7 Z/ ]
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));$ m T. h I- y" w4 I3 T- i
NXOpen::Curve *nullNXOpen_Curve(NULL);: A- u& C, U9 W! c" d
std::vector<NXOpen::SelectionIntentRule *> rules(1);
3 x) _- s4 P$ h. ]5 B- E rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
+ @* S. \/ A9 n) ? m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
. z2 L1 D; ?: h/ F$ [2 K3 M NXOpen::NXObject *nullNXOpen_NXObject(NULL);
: [4 j2 Y% v* N7 @1 t: { NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
0 i+ F3 z; A1 d, q8 j" z a- V m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
: r8 N. b9 n2 i: i: r/ k; h: h7 h NXOpen::Section::ModeCreate, false);
0 T- x V! P7 z2 v) \( q1 b
, e* W: I2 R, V$ }" @ if (bools)
! B: G+ {$ v+ I6 q8 j) |- H {) I1 L" E( n4 y6 ~+ }/ `
) |' p8 V3 z+ l4 e1 V if (m_pTextBuilder->Validate())
) ^$ r- o2 y# g: v4 @ {3 k" O' n5 s5 c2 _
m_pTextObject = m_pTextBuilder->Commit();
7 u! U' M' M4 V" R1 ^, T* M: U/ Z m_pTextBuilder->Destroy();
0 L. k! |+ X; T' _2 b m_pTextBuilder = NULL;
6 \4 k- E! R# @& O changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);7 O6 s7 L9 Y% e+ s
changeStringContent->SetSensitivity(false);1 e# U! ~. q3 w) Q* v; J, Q
changeRealScale->SetSensitivity(false);
0 k% r3 l$ R! J% q+ T) ] h }% ~# G" q2 Q: [' U( M5 n
- @0 ]! ^# k9 P/ Q8 t, e* X: o. P- ~* l; i }
6 ~9 I4 e' s* r% l, \4 @ else2 R$ r1 X- o6 R: R9 U$ ?% U" G
{
1 q0 b7 J) Q B) \7 V2 p! ~ // 4 a( U, [$ W- k+ o- h0 @6 {% V. h5 e
if (m_pTextBuilder->Validate())
! S+ |0 r; v. p b- l- a: x {
t5 k5 L- V9 I9 R1 U+ B4 Y: E m_pTextBuilder->Commit();5 p1 s% u- s9 `% M6 z( i
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);& p9 Z% m! `7 _ S
m_pTextBuilder->Destroy();: K, o8 j6 \/ s2 D
m_pTextBuilder = NULL;
, t5 h2 i0 k. Z }7 i9 H# m, M! z* Z
} 3 d: x- q7 e; E& K3 a& k9 z5 V
* s, G4 } d3 l5 O! r6 P}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
4 ?9 ~" r: m! q: ^$ i1 W, R* y$ g |
|