|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
! {' E- U( e2 q. Y; g6 z. L4 V4 o1 `8 G+ M" ^* m4 A- B5 N3 t7 ?
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
. d% F5 q+ G( b- E{4 n8 M) t* ~3 p
if (m_pTextBuilder == NULL)
0 P+ Q. \7 L5 S0 B: Y3 Q- }, j1 v m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
4 W( W- W$ D s8 T$ h7 r6 s int i = 0;0 w+ v& P: i5 S ^- ^
C/ L& V; X7 v! Q w m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
9 ?2 g/ X* a0 e. j e$ z m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);1 l1 E( D. }6 V) Q2 k" [
NXOpen::Features::TextBuilder::ScriptOptions characterSet;- M3 h y! g+ }( N1 p
if (fontType[1] >= 'A'&&fontType[1] <= 'z')0 w* {: t7 x* r+ n2 y" V$ t
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
7 g0 C5 `5 Y- m9 ?6 s2 j W' S1 d# @ else% D% H, M- m4 \. {4 _2 ?8 q# G4 a6 y
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;6 ^# b3 M f- _& d9 ?: _: H
i = 0;
# B( P" M: z" f$ g. m3 u5 N while (1)& ^1 Y- R: L9 j% H
{
$ ]: j, k6 K. r% D9 D if (fontContent == 0) break;
5 j n' a% x! s; T) ~ if (fontContent & 0x80)
8 W5 o$ e* X$ i7 W1 b if (fontContent[i + 1] & 0x80)
$ @- Y. b( f3 u5 w" q* P if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
9 n/ s) z9 Z5 A7 E! F {7 O% z7 p) k% s8 I1 H: s& ^
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);7 @1 [. D! h) R
break;, `- j, A- S+ r6 A
}; e9 N0 y1 T& @* z$ S% i
i++;) O/ v- w1 Z* K5 A b
}! e: E* @7 S$ p4 ^, L+ N& j
m_pTextBuilder->SetTextString(fontContent);
8 B8 u3 S& _: I3 j0 u, j m_pTextBuilder->SelectFont(fontType, characterSet);' ~ W0 v& r4 @8 P8 x
m_pTextBuilder->SetCanUseKerningSpaces(true);
, S, k/ d K0 j0 R2 H! t) }) n m_pTextBuilder->SetCanReverseIntersectionCurve(true);3 l9 U6 X( c1 s# x8 g- C! u( W
& u: H0 ~# z+ w8 a0 S7 A3 b. _
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),0 k% D- e F b2 j7 ]& F
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8]))," g; P( D( K7 q
SmartObject::UpdateOption::UpdateOptionWithinModeling);( e- M. L) T; a9 o
m_pTextBuilder->SetOrientationVector(orientationVector);: u" {( I6 A" c) a* Y
0 T# g4 J" } Q8 z2 _7 u0 x m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
1 D5 h. k" ]0 M- ~ [ m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
$ V% o3 `3 C7 [; u6 U4 _! P0 a4 T* y
i = strlen(fontContent);6 L( U, ~6 N W% A# |8 W" W
char buf[256] = { 0 };& O# E0 m7 `) l/ c
sprintf(buf, "%f", i * 10 * (wScale / 50.0));* a v/ d/ W7 b4 d- t0 D9 a/ \. I2 ]
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);& q+ d6 {; |" |
sprintf(buf, "%f", 10 * (wScale / 50.0));
1 A/ e' R" `( ]/ y8 H4 ?+ m m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);/ {1 H3 Q E! Z, ^2 z
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
! v: ~& k. M4 I1 p& O9 Z8 L2 y) {# c4 q6 J
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
. i* K8 ^& q9 U6 v8 K m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");, `' Y! U: t7 E# o% \. Q# X
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
9 Y9 l. z' I6 A( r$ C- U* ^ m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
' z0 D! I! ]- g5 m# J# n m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50"); f* a' ~) m% c# q
& A; W& q0 n/ o! a6 `$ @9 X9 L std::vector<NXOpen::Face *> boundaryFaces2(0);
# C' g d% l& p NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
1 _ L# L T% h- S4 l std::vector<NXOpen::SelectionIntentRule *> rules2(1);0 G3 j3 J4 r4 ?+ u
rules2[0] = faceTangentRule2;1 [: y4 w8 t* i( a+ v9 T7 i0 {0 R% r$ x
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);6 c; Y6 |) a' C* @1 I# R
3 r2 v* `+ z: k* [5 Q; S i m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
" U+ F6 z# p% p$ T+ I2 m6 |& E std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
" o' w1 @& o' T9 I$ o- t; ^4 f CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
8 d" G# N; o1 V7 r" w$ o3 |- v5 s NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));: f, j# Q9 B+ q" B
NXOpen::Curve *nullNXOpen_Curve(NULL);/ h$ M' {$ [* o# m( X
std::vector<NXOpen::SelectionIntentRule *> rules(1);/ [& G' }, ?8 t1 Q# q
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
* z: N2 Q- B9 b) r# G m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);4 e' a' Q/ T: G/ m& ?" a: ^
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
# r- {9 C: R0 m3 c' n$ C NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);5 X: v, D2 |/ r! F; @) I8 Q: N5 d6 |
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,. r4 x' J5 t: I$ }1 f6 h
NXOpen::Section::ModeCreate, false);. u: T) f+ }0 t# t9 g. I
3 e0 p5 g! S. }5 L9 ] if (bools)! ]4 A- N$ |5 `7 f
{0 L% d1 p) d8 t6 `# T0 H+ J
0 n% c( E" s7 G5 L+ g# l; j if (m_pTextBuilder->Validate())7 ^7 O, H# P) N6 N, z; v* d
{
$ \; f9 U' e: D! ~( q m_pTextObject = m_pTextBuilder->Commit();7 l; e0 e4 Z# u1 J. w- s/ F5 O& t
m_pTextBuilder->Destroy();8 [ K: Z. G# d9 {& K6 _) Z
m_pTextBuilder = NULL;8 t9 [% R) E, L
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);1 x4 n% r: R0 j
changeStringContent->SetSensitivity(false);; z& ?/ _1 P A l3 w
changeRealScale->SetSensitivity(false);
7 t- q/ |* ^( u6 U. u7 h }
# z% {& _0 ~( K) G( w X , n$ Q) k$ e+ `& @( I, B6 P
}
! g6 d9 l5 X# G& u* I1 i& d0 |9 g else* Q5 T/ f- M1 `/ f& u2 C6 n e$ m
{ 5 J- \: k$ b3 w- p" r9 s
//
4 x: S* v9 V6 L if (m_pTextBuilder->Validate())
. d+ i" [/ o' `8 t7 s {
# {- @' G9 I, S5 r m_pTextBuilder->Commit();
7 `& Z4 {* h1 [8 U8 }' {# A UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
5 `; G9 l% o& Z) X: t, J m_pTextBuilder->Destroy();
) e: o) X0 Q8 G6 R m_pTextBuilder = NULL;
H/ I( p" f6 P, |. F3 P }3 `1 T5 Z/ N( r0 C; F% g; _
}
1 Q" y. \4 b7 P
& }& X' H e9 K# b# P}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!$ Q7 Z, J2 i) ~- k$ _
|
|