|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:8 E3 ]9 U8 D& o& x* f0 F1 `
" K! T0 j0 L3 Dvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
* B+ A0 }; y2 a. }* G& e {# N- a{
" r2 D& p' D- M9 L3 b" Y1 R if (m_pTextBuilder == NULL)# v! ~% w e6 A) F; y" D) W
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);( W7 e% o2 }' A* l$ i5 _7 c
int i = 0;
' N* ~/ d& e4 \4 F T( U( L1 x& N. o4 d' o$ C! B. w9 r8 r
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
* [ K* h1 {: ?8 O1 R4 v m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);3 D; T* U+ q( H) f: r* I: ]+ {
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
3 B9 A$ b% p2 }! S7 x6 x if (fontType[1] >= 'A'&&fontType[1] <= 'z')
' Q8 U+ H/ d0 U6 ?% Y% L characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
$ Y0 T0 B9 Q; S" E: t3 e. e else
. W- c3 v( C: w2 _( B6 O# S: c6 I/ { characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
- _( X6 }# G7 D; C: G i = 0;$ r# \9 f$ E9 g4 m; X% V0 {
while (1)
% o4 r+ _6 _' E0 Y% ~ {
) z3 f- u3 x% {( S) v5 P if (fontContent == 0) break;
: f6 X' l! ~0 a7 i9 w$ d) `' R if (fontContent & 0x80). ~1 [( {" d" {/ m2 c- _8 J
if (fontContent[i + 1] & 0x80)
9 u# S2 j4 w: g& r$ @& K1 f if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
4 w! C4 t1 @# h5 m {) c- o. {7 {0 `, Q& r
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);% j* k9 L' D' G5 ^) G, Q: v* ~# w
break;
& \' t: k) u% v) D/ O }
% [. n/ _! M; G p2 E# M i++;. m/ _/ R* _! J) c7 K/ g
}
4 Y9 O7 K. t# d4 } K6 F* _ f m_pTextBuilder->SetTextString(fontContent);
) S1 Q) y/ h2 Z# y3 ~ m_pTextBuilder->SelectFont(fontType, characterSet);
( d( z( x! d- q m_pTextBuilder->SetCanUseKerningSpaces(true);# j) U: `; s* t! ]
m_pTextBuilder->SetCanReverseIntersectionCurve(true);3 f4 z7 Y H) A+ z
: i$ z) ~8 G9 r$ y2 ?1 W4 v1 u# `6 ~
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
% x5 `0 l# O* B/ _, S: K Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),* @/ K2 T- A. m( k# N, V$ o
SmartObject::UpdateOption::UpdateOptionWithinModeling);
' T9 D8 P+ a9 A. A3 d m_pTextBuilder->SetOrientationVector(orientationVector);
6 K1 M6 \# C e& ?1 q! \& V$ t8 {
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);& v/ x( M0 v6 n( }
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
% B$ U+ W' ]8 _. f" S! w/ ], r
( j; `! h! _4 |9 k i = strlen(fontContent);
2 x- z' s. @/ y6 z char buf[256] = { 0 };
$ i% b1 G7 z; I$ h sprintf(buf, "%f", i * 10 * (wScale / 50.0));7 P- R" L& }3 O" I% z. M+ h
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
8 u% F. ^% u- |% x. _- D" `% {+ Z sprintf(buf, "%f", 10 * (wScale / 50.0));
) [, ?# [. E# t9 n/ s9 ~ m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
* q" N7 [4 c! J+ Z2 c m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
3 c! X3 ^7 t. {7 I
# ]# ?* x9 E1 ]8 e: v: V+ H m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
9 @* t O, I3 [- c! ?- @9 u m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
0 j; |! t* {# @& N3 n+ \. S ]- m m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
$ z. |; X9 k) B m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");7 M1 a8 X. l. @8 Y5 R' i& E
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");4 {, C6 ?+ L' @4 Q
1 ]( p' V) h& M8 E. q2 H' G5 i
std::vector<NXOpen::Face *> boundaryFaces2(0);
( Q$ ?3 g4 Q1 F) t: l NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);
5 m( C n8 h% @$ p std::vector<NXOpen::SelectionIntentRule *> rules2(1);
4 B) P0 Z; i4 a# u5 ] rules2[0] = faceTangentRule2;
4 q% H6 w. H7 B* ?% y+ H m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
: E7 Z. Z. S# d' U9 }. L
7 @' p) B* U: U/ R4 t0 \9 } m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);2 ?3 x' d" n2 q
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
H$ v4 z* o' S( Q" H8 | CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
, i) q7 P: R1 J+ | NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));) ^- P4 t* |6 k/ c6 x+ M9 Q
NXOpen::Curve *nullNXOpen_Curve(NULL);
/ n* ~ X9 f y7 T- o std::vector<NXOpen::SelectionIntentRule *> rules(1);' Z* ]7 J5 K L' z: n1 V
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
- I5 d# K; N9 O; s m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
$ t2 g8 N' G4 C+ H$ w& W3 E @6 H NXOpen::NXObject *nullNXOpen_NXObject(NULL);: |! p- ~# G0 u9 B
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);3 g( S) Q* F# |
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,3 s& {0 j' ~1 V. h0 {
NXOpen::Section::ModeCreate, false);
0 P2 @. V0 O6 G- j# ]
! V8 O s6 h; ^8 x" Z8 E if (bools)
3 d9 o: c- G2 `4 H8 {, ?0 u {
: w8 @, K+ z+ k/ ^, F q' m
f2 L7 N) u2 a' u) Y/ {* h1 v* u if (m_pTextBuilder->Validate()) `+ z7 U: {! y4 a
{% p* e- C; R: X* H: f9 p
m_pTextObject = m_pTextBuilder->Commit();0 H& @ r) J3 J8 U/ G0 a
m_pTextBuilder->Destroy();4 H: x/ z3 E; L5 J& B7 ~1 L
m_pTextBuilder = NULL;
% _) G. }" Q5 R; ~6 D changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
( E2 {+ O1 {2 J) A/ G+ a changeStringContent->SetSensitivity(false);
* _5 A1 z! f! k changeRealScale->SetSensitivity(false);
/ e ]$ ^) `- A5 {8 K" B }; j/ M/ d( y/ b) g' Q# ~
/ Z% z$ W0 _: v5 a+ E) ?5 ?9 a! R
}
/ [/ l7 C& F" A% f else- l. U/ u; \: d
{ 8 S0 j" a1 u1 x4 H( k% |
// 4 A' ?2 r: Z7 K$ J" q K- z1 t
if (m_pTextBuilder->Validate())
+ K4 \, E8 O3 e- Z: @7 N {
/ n9 ~- n( E2 e; L5 j m_pTextBuilder->Commit();4 I4 b$ M; {! `: ^
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible); s, J6 s3 y$ k j
m_pTextBuilder->Destroy();
% \1 m/ i9 `5 C$ S- }3 D m_pTextBuilder = NULL;5 G/ h) j4 o0 N0 Z' B7 E0 V
}
7 t: w. c: H9 {6 R; b1 G }
5 _! b5 M1 S4 }+ a# l" [ 6 ?7 g8 ^1 c# i! V
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!. i' N! g4 H0 ~2 |
|
|