|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:4 u& I* D: P/ f* c0 D
& o! D8 d0 j6 g
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)* L. j+ o/ e! |8 |& {
{/ h& X0 V. S* w1 D" M7 K6 B
if (m_pTextBuilder == NULL)- j: G2 @ t, z* R t& s6 B
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);1 y# R! }: Y# u
int i = 0; P# {6 v8 O% L$ D% B4 F# b
9 R7 }% ]1 j7 c% M
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
- O9 K/ B, ?& {# t4 j m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
$ `9 N9 S5 m" y/ w7 o5 X8 x8 C NXOpen::Features::TextBuilder::ScriptOptions characterSet;
3 `8 T2 Q9 O3 _- y9 R if (fontType[1] >= 'A'&&fontType[1] <= 'z')
, k' S% S" x @7 M+ U" i characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
! }' o7 y9 k+ J else
5 V g/ Q0 f1 Y/ T characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;" W0 G7 M# N- \- G
i = 0;3 e# @5 `3 ^8 t8 n% [5 f
while (1)
" `" _0 f* `! J, n& J {; h* S6 T* @0 W0 W. d
if (fontContent == 0) break;2 g$ ^2 T% v0 L2 y5 r
if (fontContent & 0x80)
" s( d' O% N7 {; h if (fontContent[i + 1] & 0x80)" ^, F4 w P9 A9 K
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)4 Q% X( Y* ` U9 a
{5 z. S$ g- J4 e4 g, ^0 u g# v, M
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
) K# \9 A8 Q' B3 `% O2 m, W D# S/ |; W break;
* `0 u- l/ J) C4 q% U+ u7 M- b }
. O6 B' f+ k- ?9 }) h, `" P# `6 _ i++;
: y/ u. t# \9 \2 J, C: I5 X2 @( D3 a }3 ~( P; W* Z/ P7 }2 R& P& i' R0 ~
m_pTextBuilder->SetTextString(fontContent);4 ^6 W5 O- ?9 L9 w, l: |9 O
m_pTextBuilder->SelectFont(fontType, characterSet);- {( C1 B" S+ _ v& X5 t
m_pTextBuilder->SetCanUseKerningSpaces(true);& g9 p! `3 A* S
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
6 X0 `, \+ `- ]# F8 w; i4 v9 H5 F" J/ n F) H; V
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),, c4 O' C3 c1 C/ ^
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),( f( s8 L/ `9 s' R" e; h' {
SmartObject::UpdateOption::UpdateOptionWithinModeling);
% E# S" \2 O- O% h7 Q# d/ ] m_pTextBuilder->SetOrientationVector(orientationVector);1 O- y6 W6 }) s1 w3 b$ d# W
3 B- N# U7 Y8 J- _
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);$ n3 {2 w1 Z( r h5 j/ O
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);0 K" r' Q& a. R0 q
* g0 [. U. o) l- @/ U6 m% m3 [
i = strlen(fontContent);& O1 p; A! c8 X2 r
char buf[256] = { 0 };
/ f; \0 @ G4 R# J1 g, V& V7 q sprintf(buf, "%f", i * 10 * (wScale / 50.0)); H& \* x$ {4 r1 Z
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);0 w" X/ M* y( q- s' V, k/ r$ l9 T2 Q
sprintf(buf, "%f", 10 * (wScale / 50.0));
6 G3 I0 T _3 M- ]) M m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
2 U S L) A+ P7 f; `/ w, ^2 q m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
7 Z1 W* i) Q1 S
5 U( Y. Z6 ?. I7 e+ C4 D5 Z m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);" G% V1 [* X, G$ X7 Z
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
: Z. U( {! C+ L+ [! B/ ~# J0 w m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");- M$ r8 Q2 ^7 F2 l& _2 s7 O0 e
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");$ h0 _: k# A6 ?4 Q. U8 O
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
) N0 Y5 y9 f: @. S2 t* O5 E& S) L: c1 |+ Q; L. K$ `* y
std::vector<NXOpen::Face *> boundaryFaces2(0);0 R$ i( g' E1 G" g0 _% ~$ H, ]) l
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);+ N7 @+ h) p/ ~1 y$ j
std::vector<NXOpen::SelectionIntentRule *> rules2(1);$ k" f+ c9 q3 D" l
rules2[0] = faceTangentRule2;1 Y9 z6 w8 I% @, `( p. d* y" ]! a
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);8 L! {8 ~2 z8 q
" _ {: d# o, V! `! K( [! P
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
) C0 W2 ]. e( D9 ?3 ?/ |7 s std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
. x' {% J* X. B- A! P- t# g CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
* O! H( p3 `* H+ x" }4 v NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));' C$ l7 L, d% }
NXOpen::Curve *nullNXOpen_Curve(NULL);
8 R$ i7 f- k- a& L; Q% W std::vector<NXOpen::SelectionIntentRule *> rules(1);# g6 ]- u. x# Z# w- g! k
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
& f }1 C# i/ N+ O' @+ m& q. k m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);& G V: W3 n6 a- Y7 Q) H$ t) n' k
NXOpen::NXObject *nullNXOpen_NXObject(NULL);
% x2 d6 F ~+ Y. ` NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
6 A# G' u3 D3 c; u- x& \9 O m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,! ~, t9 i2 v6 L. I1 b) o* U7 ^% s
NXOpen::Section::ModeCreate, false);
$ Z, H6 N8 Z2 B1 h9 o& G* d- J d; W) j/ O3 S2 k
if (bools)7 y; C: Z' p% p
{: v6 m. O( U& P* G0 l9 L/ a
0 Z; K4 T0 l$ G% W. u$ X* ^ if (m_pTextBuilder->Validate())
8 y$ ?, T- x. f" F) f {% j2 i( E/ u. [8 O& `
m_pTextObject = m_pTextBuilder->Commit();
& B6 o- P( G1 ?0 u/ S9 `+ O m_pTextBuilder->Destroy();9 M$ M; H, J1 \4 B
m_pTextBuilder = NULL;. M# j, H. b6 N. N
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
+ ~1 z# _0 Y" u5 _ changeStringContent->SetSensitivity(false);* n; g* o" i7 ~3 T( x$ G
changeRealScale->SetSensitivity(false);* y( N* ?0 e9 J9 K4 |
}% I2 \" p4 s1 J/ X6 L" h' _
- ]8 M2 G0 Z5 d; l/ z& r @5 Q }
( V: x: K# R M& N! r else
1 a; j' i# @! q5 x( K6 l; V {
; K) J) E3 x+ ~ //
% E- S. d2 z2 {3 L if (m_pTextBuilder->Validate())( ]5 ?4 [* a1 `1 n- o
{: ?, s2 D- p& O6 b( e
m_pTextBuilder->Commit();" {: P p1 {& q0 ?
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
$ a( g: ?" H0 U# O m_pTextBuilder->Destroy();
* a- C2 j; ]! O' J# L3 w6 g m_pTextBuilder = NULL;
) v+ {' y4 W8 L: { Z }- B' u$ Y5 Q( y- z
} 7 F) g' y. V7 U* S" e* H; E
1 M6 i) f3 ^! c8 J n
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!6 }7 v! a0 \6 M) s6 {
|
|