|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
& b( N U" H0 Y- F' S- h- e$ @; |* U5 c& q& G7 @# Q, J
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
0 k. E( A J5 H/ Q4 I5 I{9 w2 X5 g0 D; C/ Q8 e
if (m_pTextBuilder == NULL)
9 d/ x, G; i& V, X- r m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);( @- @, q2 t4 p* k6 R& J5 e. ] z
int i = 0;
: M4 o: C$ L% r0 r$ B6 B. E; c; c% A6 c8 N3 T m9 ~5 S
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
. w$ v/ L5 {- Y: X! _ m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
& v% O2 ?2 f: f5 {& L NXOpen::Features::TextBuilder::ScriptOptions characterSet;
! J( m0 Z. r" o; R3 ~ if (fontType[1] >= 'A'&&fontType[1] <= 'z')
+ H0 C* }) j3 S+ U2 Z! u characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;, C+ z5 @7 w, [7 a2 F
else
D0 U e2 j& m4 }$ R characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
% h7 ^" U' j# n& U1 L9 u! Y; R5 u' c; E i = 0;
6 s0 I/ _& n @1 V) n" h while (1)' y" ^- g9 k8 Z
{/ ?9 _5 Y0 g I& B5 v9 U9 L& \! j
if (fontContent == 0) break;4 P* S* l6 D. e5 a- @ T
if (fontContent & 0x80)* _2 y1 @) o2 x& m9 f" o4 h7 b
if (fontContent[i + 1] & 0x80)
b' \7 V% h$ S" E+ w9 \4 |- O if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)8 j% d# K7 O6 |+ z8 T
{
6 Q3 o. ^/ ]1 a1 Q7 M3 \# l$ G1 X9 h uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1); R# P$ X' K% K, |" J
break;9 y: P1 ^/ n" n8 f9 _6 `
}6 `4 E+ r. @9 w7 K# A5 E0 R
i++;
4 _ i" E& `% A4 s; E }; o) ^/ k/ [4 A6 A: [* N2 v
m_pTextBuilder->SetTextString(fontContent);* c0 O [, v% I) l
m_pTextBuilder->SelectFont(fontType, characterSet);- B! W) g, K2 L6 Y
m_pTextBuilder->SetCanUseKerningSpaces(true);
- Q u9 o- q1 L m_pTextBuilder->SetCanReverseIntersectionCurve(true);& o; \0 ^ j3 }: _' Q& P
. W9 p u. }: S6 F) C& f8 I
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),7 ~4 J' I- C/ p" [6 {0 N; O! Y3 N
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),6 M4 \$ Z. j: X& ~
SmartObject::UpdateOption::UpdateOptionWithinModeling);) u% e% @$ M6 @6 b
m_pTextBuilder->SetOrientationVector(orientationVector);
, @1 P4 }' v, F: X
4 g W" x# W& w* J# u6 U4 u7 ?# `8 l m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
, e( [: @) G- y. d. |4 g m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
4 B/ y$ O' t; @9 W$ s/ I! N7 x( w
i = strlen(fontContent);
. C( Y# h/ A0 G, Z4 D. \! P char buf[256] = { 0 };
' h3 g; M8 h: P sprintf(buf, "%f", i * 10 * (wScale / 50.0));
' B# u0 o% d' z k3 N) a m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
* }2 L" z+ @: m& t sprintf(buf, "%f", 10 * (wScale / 50.0));
2 Y) d A) m9 o$ h. y m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
) |& t/ l- x" \ m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
! b$ K X8 a1 f8 S5 ?+ l
7 j; e- r. n3 A1 g% L% c m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
* I! h Y9 }+ u+ Z m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");1 r) J' V# O: h0 y/ D
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");& W0 k0 h n3 |6 w6 J/ K K
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
' z: V6 j* a E* A; x6 Z m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
% [/ r/ }: V* `6 H" }. n8 B% @! n4 @( t* ~0 ?
std::vector<NXOpen::Face *> boundaryFaces2(0);
3 n6 E7 h8 J' g! z! p NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);& s$ ~% i0 n m: _( I' j
std::vector<NXOpen::SelectionIntentRule *> rules2(1);1 d7 F# b9 x7 e1 V# Y
rules2[0] = faceTangentRule2;
) J' D$ A! |* O1 O m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
7 a* u# b4 s/ q$ s8 F. f- P; s
2 H7 P7 i' I# _( ] m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);, o1 _7 p- O: r: H$ ], a
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);# J7 @- R- B* H- B9 v9 Y
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
( V4 {; ^* E) R O+ k NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
$ r" P0 @, N! c- v2 P* g4 P NXOpen::Curve *nullNXOpen_Curve(NULL);2 {3 L7 l9 @4 U, L9 f' V2 O
std::vector<NXOpen::SelectionIntentRule *> rules(1);/ ^' j# p2 @ [9 o4 K4 Y
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
5 E( n6 Q* C/ v& W m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
% g: _1 }: b* _- |& N. P NXOpen::NXObject *nullNXOpen_NXObject(NULL);
; d& p7 s1 w& p/ p% T: o+ b. R NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);% s3 v# t0 A9 W0 b5 ?2 v
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
4 i# ]: q/ S1 t0 G' w+ R NXOpen::Section::ModeCreate, false);
( u: h% B- a$ r8 K6 P4 z
' K0 j" g8 B6 [4 A3 N4 D, @ if (bools)
2 ~0 T3 i' E. V# h9 F7 y# n' q0 p {
5 J- Z. f' C8 P0 l. o ) y; U5 B8 m, `, r1 W' Q, }
if (m_pTextBuilder->Validate())
" ?( Q* D: G. u9 @' w. d9 Q {
4 u9 F9 r) a2 Z7 q1 e8 u# n m_pTextObject = m_pTextBuilder->Commit();
' a( W! j5 w# k4 ]! h m_pTextBuilder->Destroy();
" f W, c I8 O m_pTextBuilder = NULL;# _' S* l5 B f1 g& o& G" Y
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);; z4 o8 G& f9 m3 C6 I
changeStringContent->SetSensitivity(false);: `/ u/ U4 s: k- l7 G$ p
changeRealScale->SetSensitivity(false);
2 y1 @* G# F, [: ?9 v; {5 a }
: J" K" [/ x% k8 C
9 }, Q$ Q7 u) C }+ ]8 w2 O. s7 n; P6 m
else/ l( O* n& x8 W! Q4 ^9 U( K6 ]
{
) }- t; j% U7 ]8 O1 O# ? //
9 C9 ^. D8 a3 ?) c" p if (m_pTextBuilder->Validate())6 @% d1 d! j$ q$ h) @
{
& \4 o$ w0 o5 n* m2 H m_pTextBuilder->Commit();
8 k8 R5 n+ @4 o4 @, K8 ^! a UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);+ a" @! d& r W4 N
m_pTextBuilder->Destroy();# Y! Y1 n- E- n1 h2 w9 h: X
m_pTextBuilder = NULL;
/ D' ]8 c# `8 R/ s: ?$ G) O }. S: |6 d0 m, s7 }" h4 e
}
# W: S, \! C7 \& Y& n( b0 \: m- [
& h2 E- D9 n) t* g8 K}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
V( @) \# @6 u+ e2 Q |
|