|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:) u; ~# c/ P" V
( a1 X! w# g0 z; _6 q( a' L' Y
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
2 m# U9 f2 T9 D3 H" E/ ~! w" U' D{
; l- |9 W! }3 p; E if (m_pTextBuilder == NULL)- j" o9 g+ n4 }1 c& ]! B0 `
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts); |/ m: B. Y! r
int i = 0;
1 C: j# Y# `. C* w/ d( G5 F( H8 ^# b
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
5 L' E' f) e* H- m m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);/ ]- {8 u8 \: E% z/ W( ^) w+ Q
NXOpen::Features::TextBuilder::ScriptOptions characterSet;/ ~8 I9 u, J& ~1 W2 y- O5 L5 I
if (fontType[1] >= 'A'&&fontType[1] <= 'z') f% b1 i9 X9 N, y+ U
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;& b& U& A h8 t" z, ]
else+ M \4 r: F* D, i* X# Q' Q
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;# k# e' Y% g' {* _( P( U" N
i = 0;
* a# W. i3 K6 o3 e- S while (1)' i1 p& \9 w$ }( d+ ?0 ~( a5 o
{2 F1 V! J( u/ R* e, o
if (fontContent == 0) break;' G2 ^5 u* ?! l* @9 v6 ]/ T# o
if (fontContent & 0x80)- H. G7 g: b1 ~0 b, M. Z
if (fontContent[i + 1] & 0x80)
+ }6 y; Z# x6 ] P: Z if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
4 U* y+ b6 ~5 R {
8 u! o4 y+ {! o4 a( c U uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
/ A. M" a( X* m/ L' q5 @ break;
; i% D; T+ d$ E8 L- C5 A! Y. w }
& V1 h8 G- r E6 }" a i++;! w) U7 I# H: v7 f
}9 z: O2 f' A; ?4 N
m_pTextBuilder->SetTextString(fontContent);
' ]5 Y5 g1 x- j B" O& W m_pTextBuilder->SelectFont(fontType, characterSet);7 N* h1 `2 s, H1 b+ [9 L N
m_pTextBuilder->SetCanUseKerningSpaces(true);
6 q- L6 z: n0 j2 y m_pTextBuilder->SetCanReverseIntersectionCurve(true);
% }4 z4 z3 f, ~ C7 m4 j3 @' x" O
2 ?: F2 L# P- J* d K8 c NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
) ~. p0 M: Y2 _" c! i Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),6 E0 y/ C, {4 g: X, k1 [$ E4 A
SmartObject::UpdateOption::UpdateOptionWithinModeling);
! d4 V( a/ ~, R2 `8 `8 X8 u4 M0 ^ m_pTextBuilder->SetOrientationVector(orientationVector);
# v( C n1 k: _9 v- W! F" q) @( {5 a4 X& ]/ g2 L1 {
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);0 h2 X* k0 e; g& `5 e/ i7 x
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);- B# ]. M8 v: u i0 } y
1 H) C; E( X" A6 ~ i = strlen(fontContent);& I/ d# b6 p N2 f. x8 S7 g
char buf[256] = { 0 };
/ h8 f9 W' u! S' N1 `( k sprintf(buf, "%f", i * 10 * (wScale / 50.0));
* E) R0 y( z1 Q9 e4 k4 r1 M m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
1 ]% m5 H, z% Q# O$ O$ K( E, p5 \4 H k sprintf(buf, "%f", 10 * (wScale / 50.0));" v% ?% n) `2 H" |, ~; J' D0 U
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);' z7 e* ^) f2 B' t Z7 c
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");2 J; Q% o1 R5 I: c( i# _
( P3 L8 o* d0 s" Y% Y: g `; {" U
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
. E9 H" ^- g, V- ] m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
1 J' \% n" H) f1 h* c, P m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
; r* c @9 x- K$ r( C m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
* P& H' v% I$ Y m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
; ?4 H" I& J! `2 I- c
: [8 Y4 ~5 X+ @ std::vector<NXOpen::Face *> boundaryFaces2(0);! f; ^( _! p/ z' d+ T
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);7 M: G' K1 b- [, S9 W3 Z+ r
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
# d! ?* G6 p; h1 s ~ rules2[0] = faceTangentRule2;# F v! A: X: ?' J2 S y2 a
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);6 p; \; E$ B& }& B. V' E
! ?' b1 F2 J; h' n r* q
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
, q0 B5 |7 H1 M9 p std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
) m, P2 }. H& Y5 I9 ` CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
! q1 Z- }1 e2 {, Q1 Y$ L0 \ NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
' [2 S* s# N& ]' R$ x: G" V NXOpen::Curve *nullNXOpen_Curve(NULL);
& |/ e. ?, t# V1 j) D6 d" L' D- \ std::vector<NXOpen::SelectionIntentRule *> rules(1);) j& W! U+ d, I
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);$ C* ^5 T' c& V7 S( V
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);" `: Z* Z; [$ y( Z
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
1 X# g# c: a8 N! x* f$ m NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
8 M' A8 \3 a3 o o m m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
& V5 e5 e4 p& V! |: m NXOpen::Section::ModeCreate, false);
" I# g( G" l0 n' W, ?
. P5 X* u. q! z if (bools)
5 g1 G* ? f0 q n* e' k- i1 F! ~ {/ q, X' E# |* I) l+ k2 M* G* o8 M
) p% ^2 I) t7 T E& m8 c
if (m_pTextBuilder->Validate())
6 I1 w1 s" O6 p/ _: {7 j {
: e( E( Q/ {0 R5 a6 X: P m_pTextObject = m_pTextBuilder->Commit();+ O! I9 B/ [: _ ? |( i
m_pTextBuilder->Destroy();' S) L; x- e/ I' a- `
m_pTextBuilder = NULL;
/ t4 A: c* B$ _. ^# z4 K changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
0 X% Z; p1 s# z3 B6 C) V( ]% } changeStringContent->SetSensitivity(false);" N: N6 P( U. \" C8 v0 M
changeRealScale->SetSensitivity(false);1 Z- X6 s( I" ^. s
}
1 E- Q/ \0 @4 j% B2 Y
- J0 z# D! i' a9 n/ a: a }2 R1 g2 q5 q; b1 A( O5 ?' z$ I
else5 k5 n( I5 i5 W
{
: O+ M+ \0 q1 `& R: k; S' V1 l; ?/ q //
0 q8 X A& j) o5 X& O2 m if (m_pTextBuilder->Validate())
+ g" N+ V6 v d {
2 e8 V+ r# T0 e3 T* v, c4 c m_pTextBuilder->Commit();
" p0 x1 S" @. Y; P( b8 s UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);7 o# b' z6 z! ^6 Y
m_pTextBuilder->Destroy();
; p& q1 A+ ^% H' P4 _1 e8 { m_pTextBuilder = NULL;
+ y2 \' Z% `5 Z. c3 @! A }# M! o/ h8 B+ n& y% m! @; W
}
+ V$ F7 E* T! j; r; H ; p6 t$ B4 X0 @+ `7 E* x; S y. L
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
5 [: Z; H* `0 ~5 Y0 L |
|