|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:0 E8 e* g) Y# s/ e- a {
2 A, U7 }5 ~" C
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
4 I p8 s& E, D1 L* F3 c{
0 k4 P1 G* q, L if (m_pTextBuilder == NULL)* n# Q- N* Y# |& D' e- p- f) A" J
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);& W3 v" i' E* s. Z$ F6 @) o
int i = 0;
4 e v- k' m- D# _0 x9 N+ h: u6 ]2 ?9 T! m; `% w
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);& {2 B' J' H! V# Q
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
$ w$ R, u4 x- {, n7 q NXOpen::Features::TextBuilder::ScriptOptions characterSet;
$ T) \; `' k& v7 P1 H if (fontType[1] >= 'A'&&fontType[1] <= 'z'): l2 b. i9 k& P0 N7 j2 x' B
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
/ M- Q: N% o7 @7 [' |6 t5 `6 b- X% r: v else
- U9 d% {8 @# ~/ @9 d/ l4 J' q% O+ k characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;$ ?8 u5 }+ z: F. h5 c6 w
i = 0;
. E& g6 k2 P% A, G while (1)
, ^' R6 O% Z) {7 m+ v* F3 V& Z* R# ^ {( S4 q4 r B7 S' Z" F1 Z, H( Q
if (fontContent == 0) break;
9 x3 M) Q; E @- [& M$ w if (fontContent & 0x80)
: W" B1 {3 t. I% |& E if (fontContent[i + 1] & 0x80)
7 ~: y' r2 x5 w% u if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
8 C/ i* d0 W H {
# X B" A% y1 B" u7 t4 X: O uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);+ a# j4 H! a6 M
break;
0 n+ a2 F0 I% B }# X: D3 @% q) \
i++;8 i2 b# u3 b6 Z8 ]6 V h& Z
}
: l/ l4 ?" w u. @7 \9 L m_pTextBuilder->SetTextString(fontContent);7 X, B% A) V- I0 K0 S3 t
m_pTextBuilder->SelectFont(fontType, characterSet);2 y& K" A3 W# `/ j$ b
m_pTextBuilder->SetCanUseKerningSpaces(true);
. D7 F* X2 i- P; W1 \ m_pTextBuilder->SetCanReverseIntersectionCurve(true);
7 Y; P0 N4 L1 R& j' x$ d2 U/ r( {4 D! A9 w: M
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
1 e; [3 B( s6 L9 f Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),+ b( [( L: @- P' F
SmartObject::UpdateOption::UpdateOptionWithinModeling);
3 Z$ p+ E1 T$ g m_pTextBuilder->SetOrientationVector(orientationVector);
' H/ }, m6 Z- W3 L. I$ |; h3 D$ ~9 g! I2 x+ w1 k) s5 U
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);6 G1 |& |! Q: X" q) v+ g
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
! q1 s" D: p5 \# d! k5 S3 m8 x1 G; ~ G/ G
i = strlen(fontContent);
; p5 ]/ A- Q) N* f+ Y char buf[256] = { 0 };
$ F* T; W/ \8 R; _2 G; `: v7 q sprintf(buf, "%f", i * 10 * (wScale / 50.0));
5 W6 A N0 `3 u# @ r) v6 Y m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
$ P" x* u2 n3 z sprintf(buf, "%f", 10 * (wScale / 50.0));
V, [1 g# q; {5 e m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);# u8 }+ d! `. e; d/ b1 i0 E
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
P% p7 g: u7 H6 h0 {" @- G1 @# `4 s) k$ [3 J8 d
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
3 T' f8 ~* [0 s) I7 r m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");1 |! G$ T4 k3 `- \; ?. U
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
, G2 v# S: {: e/ y: r m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
; Z( f% ^! F y/ |* a/ G m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
. {+ b) r, A! m9 t4 V% g- m5 I' d& G* [$ A4 w" u: U
std::vector<NXOpen::Face *> boundaryFaces2(0);
& q; y; R+ s9 [4 j NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
( r* i2 h T) ]6 z9 b, E9 S std::vector<NXOpen::SelectionIntentRule *> rules2(1);1 i$ a% R* X8 d
rules2[0] = faceTangentRule2;5 q, ]& X7 A/ |8 V
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
; o& K: {9 ]$ H1 A* p9 _- O9 B' i, b P: _' r' V- R! j s
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);% y: t" L0 A) z
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
" s3 e! g( i1 T& ^ CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);- ]0 L% k" f7 A8 E5 D! G
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
* k$ v! z9 {2 v% p( W5 } NXOpen::Curve *nullNXOpen_Curve(NULL);
# X0 ^, W A# k std::vector<NXOpen::SelectionIntentRule *> rules(1);
* C& x' Z$ T* K! \3 a rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);. k+ C5 J: g6 @6 y# {' S+ @- ^
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);+ x8 j2 ?; S* Z
NXOpen::NXObject *nullNXOpen_NXObject(NULL);- b5 x" O/ X) @4 h% t
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
! F$ S* `* E: G5 `/ U9 y' I! {0 ~ m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,3 l Y' y4 P" `/ c
NXOpen::Section::ModeCreate, false);6 e3 a- I# J; V, j
' }/ S. m( d- ^6 a" _- K3 T# ^
if (bools)- k2 y5 n3 W* c9 W( @" y
{
- E( n4 D* v9 h# X2 @. d
! A+ w: D8 t1 r# Y) R1 J if (m_pTextBuilder->Validate())8 p5 ]1 }' O8 t* h# \
{6 T7 |0 c! }9 Q+ N
m_pTextObject = m_pTextBuilder->Commit();# \& c3 s" n2 \- f2 d
m_pTextBuilder->Destroy();
, B- z0 i$ C u; ^8 Y. p- ^ m_pTextBuilder = NULL;$ o2 i5 m5 M j. v: Y! u
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);3 Z4 R* l7 ^/ G
changeStringContent->SetSensitivity(false);
7 O$ `* D/ r, C# x changeRealScale->SetSensitivity(false);
) f9 g: \! h6 y Z) o+ y }
7 ^3 G; a7 b; \# X, Q5 J ; s* ~6 L, g3 J% |- }6 Y3 ]) I
}
+ K; j! h* z5 D+ n2 b( d else
! K9 ^6 M" B- D" c5 F2 B3 y) J {
& l7 i# K% d& k9 x% M+ R // + e: Q+ b1 W3 H0 m: Q& A, g
if (m_pTextBuilder->Validate())
, B( s) |% L6 w7 ^ {
; X5 X- o" Y. a. t8 V3 @& [ m_pTextBuilder->Commit();
0 ?3 E+ V2 h* y# E" L1 O3 G0 u0 @9 s UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);+ r2 _; Z1 S8 O8 j8 M9 j, {
m_pTextBuilder->Destroy();5 n: z1 h6 j) {. t7 [3 z
m_pTextBuilder = NULL;) |$ m# u+ p: B& n) S
}
9 \) e0 |6 N7 N } 9 f$ d, z5 G( w5 \* {& J
4 F2 c4 A. Q# ?0 O}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
7 J: O, K9 L" S0 q. m. } |
|