|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:% H, s% z8 i }4 I
( s$ h6 y' C% m) f1 l
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
/ d% A. ^. m. M% ^- D, n{
2 t) T+ R2 E. L: ~+ q: S+ c if (m_pTextBuilder == NULL)) ?' S1 ^# U5 w; M/ V% n
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);; J: d: t+ h* e* i" `# d' t
int i = 0;3 e+ ^+ \9 _' R) ?* y" e t
2 N) E- l. i4 `# t# z% c m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
7 J& t$ ^+ x" W" V v m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);+ W+ D- T( v, r# ?0 x
NXOpen::Features::TextBuilder::ScriptOptions characterSet;+ f3 {) s6 T) a) n+ `5 X
if (fontType[1] >= 'A'&&fontType[1] <= 'z')& X' o8 C. D1 w9 i: ~( A
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
7 u& M$ }; E0 t+ }1 y7 T" j2 L else
& P) T0 |5 o, z& P/ ~# h& q characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
* T; x' N- q2 J; ~2 @ _- u i = 0;
: G L% I1 a- u2 m, p while (1)8 m# Q* i4 F, T; r) u# f" y- _
{
2 J+ C7 t% P: K H, @; v( N% ? if (fontContent == 0) break;$ k* w5 C7 u& D
if (fontContent & 0x80)
# \ H- v# q' k if (fontContent[i + 1] & 0x80)
7 t K# O: t% G if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
3 c. ?. c1 ~7 R# _9 K) g' q8 Q* W- ] {0 I4 M4 y) {* ~& o& k
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);6 P, K; I$ s v3 Z
break;
k9 O) U( p6 F/ R; k0 D- Y }' s6 \" d3 S( o! O2 d2 ]
i++;
+ f5 ~' p3 R( J$ q! r* {& s7 {: R }
6 P- [/ ?7 j- x R( T" s. I m_pTextBuilder->SetTextString(fontContent);- q- N* @; F: G+ z. R1 F9 U0 i) Y
m_pTextBuilder->SelectFont(fontType, characterSet);2 z, T: B8 y0 f1 z e" e
m_pTextBuilder->SetCanUseKerningSpaces(true);& o2 g8 _/ D5 o6 @, H- y6 b
m_pTextBuilder->SetCanReverseIntersectionCurve(true);8 N2 I5 Q' T8 |
$ F* F1 ?$ U( p6 J J# @ NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
6 _8 G1 m7 W, b4 R9 } Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),2 p, ?( _% k$ a7 L. G. N
SmartObject::UpdateOption::UpdateOptionWithinModeling);( v% g$ o/ }1 I4 F) Q
m_pTextBuilder->SetOrientationVector(orientationVector);
0 H/ n: Y Y# f* s7 e" }: x! q `. G% H- X8 u
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
6 T" l4 s* n+ ^& V m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);2 [2 m* h/ \) b
' x8 q3 S1 B2 d: H1 D U i = strlen(fontContent);6 y! r, C. o a9 [
char buf[256] = { 0 };, d! x, w+ A" ], X& v
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
( |/ L9 ?( ^# F" [. K: V m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);( j3 _7 D- S, }, W$ E+ K# b
sprintf(buf, "%f", 10 * (wScale / 50.0));/ _2 k; B! g7 b; ^* m% ~
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
x3 s; u7 ^+ S. O5 P5 Z m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0"); H8 B& _. y# I' T) _
0 R8 |% W% ?! Z0 T
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
$ q; I8 v. Y+ x; O3 l m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");: x3 q1 u5 m0 Q/ v4 r& r
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");0 ^7 c { f6 |
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
4 g4 t8 D1 W- E5 A m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");2 \7 y' R Q8 y1 q2 B- e( }8 W
0 M& o! q7 ~2 W8 h; m } std::vector<NXOpen::Face *> boundaryFaces2(0);; j. k- @% w; p7 S8 |6 \ ?
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
( b' y7 b( h. b# u std::vector<NXOpen::SelectionIntentRule *> rules2(1);
, J# i( r: c& l; a: ? v rules2[0] = faceTangentRule2;7 P$ L/ `" P0 [+ D
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);% |6 E( Q) l4 B: a$ ~
/ r* {# Z9 r2 a0 Q. ]; C m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);5 s a1 Y4 m+ o, V8 n, @) ^. a
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
/ \% a7 q, ~' z8 w! R2 ~ CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
9 d& G& g# J8 o; j% x L2 a2 _ NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
) g5 M0 v" J* ^3 E1 ?. F$ x! w NXOpen::Curve *nullNXOpen_Curve(NULL);4 m# f) }4 m. r2 d4 d
std::vector<NXOpen::SelectionIntentRule *> rules(1);
% y: ~! b" _' a, h rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);3 v0 B4 `' D8 c5 J9 q
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);* k# a# j7 j7 O) z
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
; f$ K% w* [4 J) p4 G9 x' r/ g NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
4 b. i F7 c7 g5 A$ S* M m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
- J- h: v) I% w6 W5 @ NXOpen::Section::ModeCreate, false);) M7 S4 O: e9 o0 q8 Y6 T+ y
3 `2 {! ~8 C+ _; @; V) ^0 ? if (bools)
7 {6 G7 ^+ u6 A: ~% B% \- D' [8 V. E {
% o& {$ f/ } B1 I# h3 H8 U5 a % ?- f; @6 O: C( Y8 b4 {
if (m_pTextBuilder->Validate())
' ]' @; k" u3 s. z2 B {' i# L) q! h/ I0 V+ P& K1 |( Z
m_pTextObject = m_pTextBuilder->Commit();
! U7 Y* `1 C9 o/ V' X8 Z m_pTextBuilder->Destroy();
, v4 z0 A/ _0 e+ u- F7 D6 w! A7 m m_pTextBuilder = NULL; a% Z# ~7 ?9 j8 N& J8 ~) g% k3 w8 i" p
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
0 U( B( N. V( d0 v) K# g changeStringContent->SetSensitivity(false);7 | F+ m& r' N4 t8 y: N% i) z
changeRealScale->SetSensitivity(false);/ i: N6 A& U& ?' N: j" A
}
4 c Z4 a1 E o4 Z1 R$ l3 f# w% A, X
6 {, Q" E& g+ ?, q }8 ~" X- e# u& S, E: Z
else- d& e% x- v h) P& i" @( f
{
( q+ @+ f& y- c% X$ W& p6 o //
! S4 c% Z4 _2 \- ? if (m_pTextBuilder->Validate())
4 Q6 \* b- K2 S! u i( j3 @ {0 x3 w- A# @6 a# B
m_pTextBuilder->Commit();
# m3 j0 t ~% |' s# O2 I% c$ w. C UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
9 l4 f8 _1 E& v/ A( ?' q% N) K a3 b m_pTextBuilder->Destroy();
) X& S# ~7 Y. c! V( i' R0 G- G m_pTextBuilder = NULL;( W# `& ], c" d* v% ? ]
}
/ i* {8 c; k% w! y }
5 k1 B& p+ _! M4 h/ y
6 v7 ~: K% x' X; Z; U}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!' D+ {- { E5 g, ]6 l# j! j
|
|