|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中: V3 q' c& E+ L& }% C# t
6 y& K* m ]. k3 x$ l7 c8 Y3 E0 d
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
9 j K# {1 y; A3 _{6 t# R1 j+ O2 y' X: {1 [( Q3 s
if (m_pTextBuilder == NULL)) c, U( k, N( f3 x
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);& B/ P3 `7 O6 z5 j% A! L# P! b
int i = 0;
" K- j( r' ?& I" o$ H/ k" L
* i& \3 H1 t# y& l4 U m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
# O8 c; R2 |* Z$ ?! \) j m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
7 h0 O5 w4 U. d4 |9 [% o( h) H NXOpen::Features::TextBuilder::ScriptOptions characterSet;
7 I2 o7 [# C1 \. f% l& `/ { if (fontType[1] >= 'A'&&fontType[1] <= 'z')0 E( s5 r1 ^% f' D
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
u+ ]8 r5 L9 U: a- v else/ }# s' p2 u/ b& I
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;- p" e) {! s; L; P4 q
i = 0;
0 X8 T- f) c2 Z while (1)
9 D5 d8 @' G C9 f# w5 \ m9 x& A {
, @' R- s2 }4 s" H3 | if (fontContent == 0) break;! S, }7 c, B: `5 ]8 T$ X
if (fontContent & 0x80)2 ~2 Q7 ^7 R+ i& W# F0 V y
if (fontContent[i + 1] & 0x80)
9 L8 o* Z# N( A4 ?+ p4 V# K if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)( |6 e" M" f7 d5 F3 N3 ^+ B
{2 q" F2 ?7 I4 j2 I
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);+ n9 J2 ^8 ]7 S) ]
break;
" ~' {# C& c! U }0 p( Q% `/ t. \; G0 |
i++;
9 _$ N" n o# ?) z( U }
1 F6 y. T5 ~2 a) p, U* \ m_pTextBuilder->SetTextString(fontContent);
- c5 \2 z+ f1 l; M; g m_pTextBuilder->SelectFont(fontType, characterSet);& Y7 U5 |) a$ A& a
m_pTextBuilder->SetCanUseKerningSpaces(true);
4 g* W9 _3 O0 j$ f- L2 b m_pTextBuilder->SetCanReverseIntersectionCurve(true);; O1 }; ]9 s9 t: |; f5 T
0 A+ m5 f, ~2 u
NXOpen:irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),) ?' R$ L7 r) E) u V$ Z* V3 `
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),4 @! m. E7 b) D; E' m# }
SmartObject::UpdateOption::UpdateOptionWithinModeling);" w+ Q! N- w4 E7 l# z) l& g
m_pTextBuilder->SetOrientationVector(orientationVector);
" _, Q: r2 n0 C9 P- C a) ~0 t+ f' j6 F: i- D: x) m. `$ g/ D2 L
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);- u6 b0 x' w9 V) m1 c+ k
m_pTextBuilder->lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
1 W* e" E( p5 _& w$ m' ~+ w" }4 D0 G* w2 B: O7 l, s6 J
i = strlen(fontContent);
' A& i9 o: n, R8 w6 m7 T char buf[256] = { 0 };
1 V4 b2 l6 _; D$ k3 A sprintf(buf, "%f", i * 10 * (wScale / 50.0));
7 C. @/ o8 E# F m_pTextBuilder->lanarFrame()->Length()->SetRightHandSide(buf);% H; ~; c' Y# u0 `. H% c
sprintf(buf, "%f", 10 * (wScale / 50.0));
( r! G# M1 J" }0 G( B m_pTextBuilder->lanarFrame()->Height()->SetRightHandSide(buf);5 u+ B; v* y5 R# b" E
m_pTextBuilder->lanarFrame()->Shear()->SetRightHandSide("0");
& @ _# Q! h* n" G
/ S/ W; N7 W* f m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
4 W& {% m, ], Y P3 V9 Z3 n9 @ m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");$ q3 ]0 A" f( C2 p4 L
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");" E: D5 F y( M8 O$ K% U
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");; y! P+ h/ m9 ^! m) r3 k
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");2 o+ [7 M5 M1 b- u9 w2 V; u
8 P9 _' U$ _& I4 K8 Y g
std::vector<NXOpen::Face *> boundaryFaces2(0);
% O1 j: a" b7 I6 Q- e6 q NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);# O8 l3 T4 c) O
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
8 I: N% K! \6 X9 Y! E rules2[0] = faceTangentRule2;0 Q3 b- c( H9 v/ L( L. F2 W
m_pTextBuilder->lacementFaces()->ReplaceRules(rules2, false);& \3 Y0 v. s% k
" D! Q7 R! A+ ^$ q% ^6 X6 N6 s9 m m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);' M; e2 q! ?2 [, `6 r' @* o- ^
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
: m9 M, r/ J' Y7 [4 D9 O- q CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
3 ]3 W9 ^5 }" J& _6 E( ]8 p NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
8 x5 [* Y: G2 e. i* V- N8 y NXOpen::Curve *nullNXOpen_Curve(NULL);) ^; ?5 h3 H9 K e* ^+ C
std::vector<NXOpen::SelectionIntentRule *> rules(1);6 ]5 D! u; G1 o" [: w& e, W
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);, j3 ]/ {7 a# K; M
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);$ J, j) W' ^3 m6 {) W* U8 _
NXOpen::NXObject *nullNXOpen_NXObject(NULL);3 B% {! s9 ?" c b- s! \
NXOpen:oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);/ P9 j8 T. t( U6 ^
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,9 K" [+ w( F3 j" J8 f5 c8 H
NXOpen::Section::ModeCreate, false);" a! P# E* F4 a x: s
, T% L* c5 |9 {" Z( j) \7 Q8 k& n# g
if (bools)9 i1 h; i% {% X2 u
{! E. A l1 |' c
0 L5 u, g7 R/ g9 c5 a2 e
if (m_pTextBuilder->Validate())* D* c2 F+ h; H) D
{) _7 ]; p3 ~6 G) G# s' J+ t
m_pTextObject = m_pTextBuilder->Commit();0 L. ^9 u+ i$ g% [5 ?5 T& v/ W
m_pTextBuilder->Destroy();: g' \3 N9 E3 h& [8 J( z
m_pTextBuilder = NULL;! Y: J& \! O: H
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
; w2 }4 f3 C e; E j. E: T changeStringContent->SetSensitivity(false);+ C/ S6 R% {/ K. Y
changeRealScale->SetSensitivity(false);* L. x- Y6 l3 }
}
; F& c- o0 s! n( W % O2 h9 x! ~( M) p! P, S
}: z' x1 F x' m5 k# z, T
else
( _* L2 G5 g% @( h$ ~ f { , n- { p% j* E( d: d
//
( O! E c4 [. U% c if (m_pTextBuilder->Validate())) v z: A% G! f% S7 H
{" i2 h3 n7 V3 j6 I5 O
m_pTextBuilder->Commit();1 a. l5 I* H" n4 A9 \
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);0 n( ?& h' A- j8 A3 J$ J0 _3 G
m_pTextBuilder->Destroy();- ^ l9 d7 m. ^# M/ O, s4 M" T
m_pTextBuilder = NULL;- A" H, O: i" O% g5 ?# b2 d- ^( s
}& L8 J! U6 T; y. \
}
; d( y& e' y! I- W$ K' C- I ( [0 C" z. T' Z# K- O
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!' [" J9 V- ?4 A! D8 C
|
|