|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
×
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
H# m# x6 W/ g$ B, ?! \6 u& W0 A, ^8 I) ~# k9 l% S2 \* Y
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
% R" O* g% }6 k9 F1 B9 A6 V{
. @/ {. }: N6 A if (m_pTextBuilder == NULL)! w7 H% f* l8 a. d- s0 f3 S
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);$ z( M! y0 O, ^* X) T
int i = 0;
4 S" ^/ z, n8 y9 S& K; Y3 |) m* ?% }
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
3 f! M1 S3 L c; U4 l7 t6 a7 e m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);5 Q. T! ^. N" S
NXOpen::Features::TextBuilder::ScriptOptions characterSet;8 P7 m( P3 [: E" \# x+ l
if (fontType[1] >= 'A'&&fontType[1] <= 'z')
, x8 F' z2 v$ `3 D' K/ b characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
* V2 L6 ~3 Y# Y+ e) u: t else
4 ~5 @5 Z! M+ V! d) p( }2 @ characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
, G- S* _7 K2 a1 M: d B7 K( _ i = 0;
6 c7 z3 S& E, h- Z5 T while (1)" d# ?; \8 E$ `3 K ^9 R% N$ k9 _
{
) Z6 s8 u) @5 c if (fontContent == 0) break;+ }/ a2 Z! i4 W) o" I% n
if (fontContent & 0x80): a$ Q4 e! b' r3 l
if (fontContent[i + 1] & 0x80)4 c9 B" I3 ?, u1 {9 G9 A; M* d( w
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)6 Q4 j0 O# |# s9 U; A) ]
{7 }2 f3 V7 r, ?9 ^3 m" b: V
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
2 l" }; C' z2 A a* X4 L1 E1 ^ break;
7 _8 m' s" b* M% I: B }( F& d2 I+ y( z9 \
i++;
7 C9 z( Z4 b2 `7 @! s: D# E }
; P3 D0 J" e9 b% ]: ? m_pTextBuilder->SetTextString(fontContent);
9 k. f7 R( Y5 H# m- i+ H( O m_pTextBuilder->SelectFont(fontType, characterSet);- x- Y! c2 R& \; b! c
m_pTextBuilder->SetCanUseKerningSpaces(true);: D- v) W0 b' N, `, ?
m_pTextBuilder->SetCanReverseIntersectionCurve(true);5 X) N9 z/ o- n, ^
# O+ J" O, v3 M8 w J4 h; X NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),$ b! R& b8 h3 Z5 e: P% V
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
/ X8 }, |$ N0 m SmartObject::UpdateOption::UpdateOptionWithinModeling);
5 V% k# K% f( l8 T+ T m_pTextBuilder->SetOrientationVector(orientationVector);! m* w: V7 k E4 z a* G4 [; C
I r: E! }7 p/ r; U) _ m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);/ |8 `; V( J/ o& X" }, u
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
* ~1 f/ h/ E. _. w% m( q! o4 G0 U6 _ v! j: k6 a
i = strlen(fontContent);
7 d) G# V o- h' U; i6 ` char buf[256] = { 0 };% z" Q' I1 X+ L; p
sprintf(buf, "%f", i * 10 * (wScale / 50.0));
( h2 F6 w4 H: ~2 i8 P; @* x m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
8 {# @3 H* Y5 ]* Z" o5 P! @5 r0 `; v sprintf(buf, "%f", 10 * (wScale / 50.0));' g) o+ r! Q0 k) [
m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);8 e$ L5 C: u6 x5 ]
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
0 M& ~* x) z8 ^6 d ]% G. _) B+ r4 p' I* Y- `
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);% }- j; N6 b( U0 d
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
+ y* Y6 j% a- } m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");; n" N$ j1 ^! D
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");+ n/ a9 I: f& }4 j$ w
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");' a2 x, m, P: N, z9 z$ E9 L
: j* G7 e6 b8 Z0 n* Y5 H std::vector<NXOpen::Face *> boundaryFaces2(0);8 S( q m5 E: o
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);8 f9 H5 g1 u L0 F3 ?) ^6 T# ?
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
2 f4 Y$ u9 b8 J: w3 [; b rules2[0] = faceTangentRule2;8 n! `$ Q( ^: u# v0 d1 j. e
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false); }7 `% g$ o9 {7 g' X
# o6 o& _& _% v m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
' X& o t% o3 b: X3 k- p& K4 a* p std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
2 n6 S. c4 c" O" M3 ~; Y2 F CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);3 t! I- y$ `! t0 M* K' X
NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
6 H3 `+ i& l @( {8 p6 a8 A7 K NXOpen::Curve *nullNXOpen_Curve(NULL);
( G2 a1 P& G) y( ~( Y; M, k std::vector<NXOpen::SelectionIntentRule *> rules(1);! w1 i: c' e2 n
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);- \ F8 }' g6 O. ?7 ]' n
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);3 j3 u2 g3 d6 v v/ H/ R
NXOpen::NXObject *nullNXOpen_NXObject(NULL);+ d9 y0 D$ y3 W1 U
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);: z5 d4 ]' a, S
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
; ? w5 d$ J1 {" `4 H3 t. y NXOpen::Section::ModeCreate, false);0 x7 }; T) J6 m1 C
- q0 m0 q9 D% t if (bools)
# N6 x' }' c) R7 o* w3 n {
L! F! N. X$ Y
9 q& e9 }% Q, z8 S9 e! A( A6 y if (m_pTextBuilder->Validate())( y- v0 ]/ o" S3 D7 E7 ^ i
{1 M* g( R: C# _" w! @
m_pTextObject = m_pTextBuilder->Commit();
; _) f- d ^2 G6 w% ?$ y. @: F; s m_pTextBuilder->Destroy();
2 K8 M8 f, e# }: r: i5 Y& K8 {( D m_pTextBuilder = NULL;* w' c1 t0 i6 ^9 S, p& |
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
7 \ X0 Q* u* X6 E! s changeStringContent->SetSensitivity(false);
7 R. f+ g# h9 P" f% p changeRealScale->SetSensitivity(false);
0 a \/ V* K* ~2 N7 s3 J5 z }
+ o) j" ~9 }9 i" U6 x/ T / N3 O$ C4 o9 I& V
}% p6 U& K6 u& [6 M+ e
else
6 S; \6 i" y# \8 G" _( I) b { & S' M, T: n; I/ [8 H
//
/ V+ O% V2 {; L% U0 `6 w' ]* x' ^ if (m_pTextBuilder->Validate())1 q! e) H9 J# h t
{
# ?& [ D+ I9 h, f3 ~! D m_pTextBuilder->Commit();8 [4 E z7 V1 |% Y
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
9 L. T9 o% u6 A3 M# o1 S9 l- M m_pTextBuilder->Destroy();
$ X, s" |1 w0 l7 c+ f7 W3 S m_pTextBuilder = NULL;* t8 c& W# A" f2 m3 n
}
/ h v s- o4 a5 v+ O }
) S/ [2 i1 D- Z2 w0 m
5 w$ k) @7 s! Q% @! d. Y}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
* k. n/ x. o2 e; Z5 k: l |
|