|
|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
& _6 \3 O$ u# y, W# j- u( }
; X4 f2 ?$ f/ M t9 g; t2 Yvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)$ d) Q" h, _, Z8 H* |& I
{8 X' o( [% V# x. q
if (m_pTextBuilder == NULL)
, C- \, s. K1 J, v7 ~ m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
; B3 W0 u) y+ [- {# a int i = 0;, i" ?- n" ]0 ?$ e# Y' W
+ u/ l' \% f0 T1 S
m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
5 k2 e1 N: x8 [# f1 u m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
( y; h$ ?' y0 [ NXOpen::Features::TextBuilder::ScriptOptions characterSet;6 H5 {$ {2 A2 F
if (fontType[1] >= 'A'&&fontType[1] <= 'z'), S3 n* D' d ]# C' J% v8 a& \
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;
) V7 Y1 ]5 v: d, l" A, `4 R else
/ @1 P9 K) M: p/ S% v: y/ Q characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;5 t% j% ^, w* E+ Y7 h2 W
i = 0;
3 ?' w/ \$ c5 Q while (1)+ R! p* P( ?9 d8 f6 i N! b" o
{5 Y8 [# b R- N( o3 A2 \
if (fontContent == 0) break;% f' }9 Q ]. Z5 V8 H- a+ [
if (fontContent & 0x80)4 ~# f; n+ ]' g
if (fontContent[i + 1] & 0x80)
7 P8 y6 O/ r/ n1 N' J4 Q' o if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
$ V1 w4 y% f' _2 T {
8 K" B- M# F. q+ i* `$ x' _- J uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
( E, a! L9 _9 ]1 i break;
4 ]) f; Q; Y9 R* b; q+ u, a7 f% a }. P' S* T8 L& C {8 S
i++;
" O0 N3 h9 t/ ^5 U2 U }% o5 t9 h8 m5 ]% K# p# u% H) x' J
m_pTextBuilder->SetTextString(fontContent);
' c' t) c" _7 N1 }8 [$ g0 N m_pTextBuilder->SelectFont(fontType, characterSet);
9 {! o0 ^2 E6 p4 y8 I6 ~0 N$ h7 U m_pTextBuilder->SetCanUseKerningSpaces(true);$ k- L" U& m0 B% J
m_pTextBuilder->SetCanReverseIntersectionCurve(true);% J& [2 R6 n; F- @
. P' f" n3 v; i" o" {
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
4 E9 }& B5 d6 A& D2 Q. f" p6 ~ s Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),* ?2 E: F; _- t0 V" x
SmartObject::UpdateOption::UpdateOptionWithinModeling);( v* r$ T7 T0 c: F4 A8 |0 e8 Y
m_pTextBuilder->SetOrientationVector(orientationVector);
5 M$ ~/ Z& ?$ ]% R9 ?8 a5 f8 r" C5 }& R7 o2 E
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);% \ o8 Y# P1 {9 @& U( D6 D& x% [
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
' L3 I& m6 {( r! {9 _
& |7 y2 |5 q+ @) V3 ~# h i = strlen(fontContent);9 v2 ] Y$ k; @0 O( i' [
char buf[256] = { 0 };
5 P% t9 n8 G+ }7 X( v sprintf(buf, "%f", i * 10 * (wScale / 50.0));
9 ]$ k P: W. m1 A5 R* B' n m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
' h& G- X% x' |* E+ K6 e sprintf(buf, "%f", 10 * (wScale / 50.0));
$ V! u) _; }2 j3 p* m8 A4 g f m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);( s+ s/ `& M) R( l; R! G
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");" }+ [! ]( |9 x8 D d& D
F# j1 V. O3 H4 e
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
" N8 f0 X6 v7 H: n. z# w# y7 e m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");+ `8 Z, F9 E/ l$ T$ D7 f9 {6 w$ a7 x2 v
m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");+ Z4 H9 ]! w0 j: f) u& L8 U& S
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
) T# C- E) V0 o; G; [9 @; u m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
$ }$ H/ `' t. w; r; K7 |. M: y5 \2 ^/ c, h
std::vector<NXOpen::Face *> boundaryFaces2(0);! P$ @# O1 V5 L: O+ A
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);8 J% J' p: ^5 _: I2 @/ }
std::vector<NXOpen::SelectionIntentRule *> rules2(1);! C6 ~ ]! B2 d" E0 ?
rules2[0] = faceTangentRule2;4 {5 I c% D# ~
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);% e/ M6 ]* T# [# {9 o% C
1 G& f+ w& ]8 _( q _( q, d! Y m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);! n$ ~1 w; ?" k @4 S0 z3 O5 K7 {
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
& P p& c4 [) H4 f' N CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
; i& l' A* G+ w* ]) j NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));; |2 q5 ~) L- o2 Q8 @
NXOpen::Curve *nullNXOpen_Curve(NULL);" E9 a1 i; T7 J: A
std::vector<NXOpen::SelectionIntentRule *> rules(1);; B5 Q5 i# l8 C0 U' x: t
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);
/ W+ }3 r" l o7 z3 j m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
1 ]* { d6 x+ _ NXOpen::NXObject *nullNXOpen_NXObject(NULL);" H$ \: g& } @ n3 [4 U1 f. _6 A
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
+ j1 f. Z+ r+ A3 x m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,# u6 `6 H" v8 f( _+ C' |
NXOpen::Section::ModeCreate, false);
0 G# K+ y# e1 n0 c/ b3 M4 D: V0 [; r" H% F4 g
if (bools)2 G" P1 w& P3 Q0 W5 K% F
{* a& p/ `7 V' s9 X4 r6 B* E
Y1 G/ `3 H6 u) ` if (m_pTextBuilder->Validate())/ s) u6 }* g) W2 O# J
{
3 f+ `- t5 _9 \% o m_pTextObject = m_pTextBuilder->Commit();7 {4 ?; s# Y4 L4 R4 P! U6 R
m_pTextBuilder->Destroy();; L1 `# \- j. e" O0 Z% R) C
m_pTextBuilder = NULL;. L- U& v% |4 v9 M, `! R
changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
9 ]$ p7 n: n! P( X2 |, z changeStringContent->SetSensitivity(false);
( B4 Q- s1 O8 N8 x" d: v" m changeRealScale->SetSensitivity(false);. M2 k0 F4 N& n7 _7 O3 T* _6 u
}
, e- f' e* r$ x+ r 6 ?" E/ ~( J& f& B" {
}4 [8 q ^% H8 W8 s8 V' Y% o6 N# w6 F/ \
else6 N% W+ E9 z0 E) F9 s
{
' d4 F, n3 I; \+ {9 B2 }: N // 8 v0 T! |. |& O h: m: P i
if (m_pTextBuilder->Validate())2 `5 c, Z; T4 b8 E" b
{
" _; n5 ]/ e, `8 w: c* m! \0 W m_pTextBuilder->Commit();
! N4 V$ ]4 N8 o+ a5 n UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);: L1 ^8 v. |8 f4 s- }3 M% F- g# B
m_pTextBuilder->Destroy();
$ O6 v( J& T2 g# k0 e m_pTextBuilder = NULL;; [$ m6 A6 f# y5 D$ H
}' ]2 |7 u8 f: \% l, r
} . _& c) T" H; g$ l r6 I- u+ s
5 W8 ~* W; P7 e H) Y
}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!% H& Z& r/ }* ]
|
|