|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:, S; L2 v9 X) X7 L6 ]0 u
! z" k! |; V$ A+ O1 G/ k
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)9 }8 k5 V' C5 X& B9 w; a
{% F* k0 b% `7 _# a0 ?: e
if (m_pTextBuilder == NULL)- B0 e6 h% s8 U9 `& s- i
m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
9 c" q9 c7 y J! W( d5 E" ?. B int i = 0;4 X8 [& ?* j6 C. s' A0 V
! h* g; |$ g9 N# q$ B- a
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);" L4 f. J1 z& I. |
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);$ p9 ]2 y" \8 w* Z
NXOpen::Features::TextBuilder::ScriptOptions characterSet;
; v' D$ {) e3 x2 w, T& `: z/ ]% T if (fontType[1] >= 'A'&&fontType[1] <= 'z')
% I/ I" J- c) B characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
3 V$ M+ o; Z! x else
$ h' j& A+ ~& ^( T% V/ c# l7 E characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
3 G7 s; S( G( P0 b: r* v) x i = 0;2 v9 C. J7 P, w
while (1)
8 z* ?+ ~' @+ y {
9 l9 Z: ~$ v- x* i6 }$ Q- F6 Q: o if (fontContent == 0) break;8 k/ o. ^5 E; O, t4 |" [
if (fontContent & 0x80)& F1 b" L. I" W! z' J5 A. |. Q
if (fontContent[i + 1] & 0x80)- n0 N: ]$ ~3 g& f8 O! N; w: N
if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
$ _& t+ U% `: l4 \+ k3 } {% K1 F: X- S8 s) n! W. D3 E% u: G3 _
uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
* z2 k! |( C1 |( ~( ^/ S break;
m' h5 \! J; X b: U& c" ^6 M% g- y }
$ K4 L3 E( q9 n3 R% X8 h; h i++;
1 d* j, i3 L; F l5 _* q }
) i. s5 X! a( {& B+ ^/ k2 u m_pTextBuilder->SetTextString(fontContent);
: L$ X1 r; d/ b! I' ` m_pTextBuilder->SelectFont(fontType, characterSet);
1 g- H4 y5 D$ ?+ S4 J4 b m_pTextBuilder->SetCanUseKerningSpaces(true);
5 d) K! Q# ]$ t" t I m_pTextBuilder->SetCanReverseIntersectionCurve(true);2 l( t0 I7 D- w; f: |1 \2 R6 h
* d4 v2 E! X$ q( S& @* d
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
B5 W* \ i1 p+ _1 q& `5 O z Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
+ y, \: d0 h* I# ^1 ^ SmartObject::UpdateOption::UpdateOptionWithinModeling);4 A" Q2 v. N6 g
m_pTextBuilder->SetOrientationVector(orientationVector);8 G ^7 ?) Y, e7 y
$ B, c) C$ }7 N9 Q+ q
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);
$ \9 _' v9 V) h0 K+ B m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);3 l7 g3 H, u& e( A
8 ~+ ?( f" P- h2 m/ m i = strlen(fontContent);
) {# Y, w, F3 K) T9 L" B- @; u9 N$ ? char buf[256] = { 0 };
0 [8 U2 |8 |7 M a sprintf(buf, "%f", i * 10 * (wScale / 50.0));. Z/ W1 l) D% `+ X' G4 F
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);2 X1 |& c' R% K5 F
sprintf(buf, "%f", 10 * (wScale / 50.0));
/ s% ?0 |: [* A- X6 {; v m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);1 g- q! |$ {) T" L1 G
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
) s, d$ ~ z1 a- d M g$ ^' R K7 _1 ~: u
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);- M( k. ~. y) T2 A- g( T
m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
3 {! m: X% Z) D# m7 ~0 r4 ] m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
' `' [2 k( A3 N9 _! e" P" b% [ m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
3 L4 C. j9 _+ ]& \8 X m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");4 _/ ?& s5 w0 k- k9 W
: S' V2 c9 G4 H, H% Z' P
std::vector<NXOpen::Face *> boundaryFaces2(0);& B8 U, y4 P+ @+ G+ _5 f6 V9 z8 z. W
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);6 r+ G* T; K7 q! S% K; E1 x- i/ E
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
, A$ d* A, b. l2 P3 W% w/ {9 `9 E rules2[0] = faceTangentRule2;
' b, [& ]! o4 Q+ Q3 ~2 b8 V( j, X m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
6 b& B2 j6 L. _) I* S$ A: s2 L! h8 Y" L- j0 B5 Y0 {( ?6 a
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);
# \& n) v9 P8 ?- @ std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);) p% @" p5 M: }* l1 c3 h& a
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
* [( @; E8 o! t9 H2 c! d NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));# U! L. A3 @& s) p
NXOpen::Curve *nullNXOpen_Curve(NULL);
2 z$ ?0 |& l+ r* L: x# R$ g std::vector<NXOpen::SelectionIntentRule *> rules(1);9 ]4 T$ [- ~6 v! y( F* `& s
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);& Y! g& q: @% J" ~
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);* b8 \ s; n; v+ x3 g
NXOpen::NXObject *nullNXOpen_NXObject(NULL);8 z) ?' D/ i$ s' s
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
/ G/ J8 Q4 Y7 e- O m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
5 v' B, }7 P' s1 T% u5 c: p7 [ NXOpen::Section::ModeCreate, false);
( z+ F% J9 f& X6 a" @4 } N6 u1 O9 h. R: P2 t
if (bools)$ W* u$ p: M; x0 Q
{- u0 G9 p z% p! L4 Y# J9 @( B
2 y( _5 r% k: M6 j d
if (m_pTextBuilder->Validate()). N+ {7 N. @& l S5 u( x; ?3 {
{
! y( P2 t1 @2 O8 K1 ~0 E m_pTextObject = m_pTextBuilder->Commit();
3 i# M6 F1 ]* h( \3 y/ S# v m_pTextBuilder->Destroy();
4 P, j# s* T4 f6 e* J0 p/ E m_pTextBuilder = NULL;% K; x, a F; b" Q
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);& u6 U E, ^: O5 r* z
changeStringContent->SetSensitivity(false);- w+ a. k4 e/ R4 K( X" s! A! N
changeRealScale->SetSensitivity(false);; {8 o6 Z3 z$ Q6 g
}4 ?" T$ O% f4 o# g9 G+ V
2 d- f+ Y& M) Q! l' U: V
}
7 Y9 Q; ^, @, a else; n( ^7 Y6 J6 ]
{ & I% r1 ~# Y0 {! s8 ^
// 5 i& Z) E8 z8 a! ^
if (m_pTextBuilder->Validate())) x2 w9 G9 B" G" a+ C, e9 X- Z
{
, J% ]+ R- D; X1 s/ D/ S: ` Q m_pTextBuilder->Commit();
: ]' _/ F7 Z7 ~: E q# b* U UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
. F& Z; P( j e* q* ^% x4 V; B m_pTextBuilder->Destroy();
# [2 O0 o, B0 |# }+ c- k1 g3 k m_pTextBuilder = NULL;
1 Q3 Z0 `9 j* o( t4 ] }1 ?; \5 m+ `& k3 d1 S
} ( P, S# L7 g9 O- h
2 S4 v% _% ? R" T. J- T}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!* p; b1 k: Y' ~- |3 p2 `* A2 k' ^
|
|