|
浮游
发表于 2015-8-25 11:30:57
|阅读模式
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:: M+ k! k5 z6 v8 [4 W
" e) b# C: Q# w1 N
void Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
9 Z! S+ x! V0 N{+ H2 q; o/ n- |5 Q
if (m_pTextBuilder == NULL)
' _8 T5 I4 d7 [: M d m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);+ t6 Z: q( U# t3 R
int i = 0;1 `; d5 m8 C- c! i- N) n. F4 d, W. i
$ B" k6 h, {$ E m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);
& G. V+ e" y# T4 {0 |0 M) j8 Q m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
0 y2 K) U, H$ y6 h r y NXOpen::Features::TextBuilder::ScriptOptions characterSet;
0 s! A4 k. q0 ?) f2 g if (fontType[1] >= 'A'&&fontType[1] <= 'z')
1 t) i7 e Z+ [" |$ s S3 D characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;% `+ e% K' A. M, U
else1 t9 `' w7 o# O y0 I& t* F
characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;
4 p, b8 T* @; C+ @( F& ` i = 0;3 i- Z3 i4 r" t
while (1)3 P- }+ z9 _" d4 i
{3 d6 d* r) @$ b# y& R' o4 z% i
if (fontContent == 0) break;1 W; G; W8 Q1 w: S" i
if (fontContent & 0x80)/ q5 z" W: |( c; k; ^; d* Y& T$ ?
if (fontContent[i + 1] & 0x80)
6 e* a' t( E8 Y if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
, P- d! b. n7 h' I! O' { {
9 W5 p+ V& l* i- L( L3 K5 O1 m uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);; u4 ^+ @$ m' k! I# c/ ^
break;
~6 t* D0 @% E T+ l3 J. w; x }
* i7 T6 @; r. S' J& f i++;
. o ?$ g. p& i8 f }7 L* z, G2 d6 l, i' o2 }6 {$ r7 S( H
m_pTextBuilder->SetTextString(fontContent);
0 r9 l P4 E B& l/ q9 ?) f m_pTextBuilder->SelectFont(fontType, characterSet);
' {3 S/ g f' A* ]& E( B m_pTextBuilder->SetCanUseKerningSpaces(true);- X6 k; S3 W1 L' X3 x- ?
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
# x7 M% H7 Z0 m2 N+ D0 ^: Q! m$ ]4 a& f& ]
NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),
8 T4 Y0 u, C2 X" {: E, T Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),
. D: E+ ~# S% L# C3 l% _ SmartObject::UpdateOption::UpdateOptionWithinModeling);% s8 }8 o$ A# `) ~3 G
m_pTextBuilder->SetOrientationVector(orientationVector);& ?6 D* q5 y9 V8 L$ y8 p: p
; s, r1 {' q" E0 R0 E9 j4 e5 ]
m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace); g" ?: L8 w4 |# Y- x
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);: p/ L7 {. H5 p
& {3 J5 o8 Z2 i: ^
i = strlen(fontContent);
" w# z* {7 _# F J3 C char buf[256] = { 0 };- V3 F) w1 \& M9 p C" D
sprintf(buf, "%f", i * 10 * (wScale / 50.0));7 s, Y# i1 N. i% {
m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);
1 p1 U! B2 D7 u, X/ W5 s sprintf(buf, "%f", 10 * (wScale / 50.0));
1 C' q4 Q8 o# \! }' e% v, r3 c p5 l( P m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);
1 ?- Y4 l }7 \$ ^ m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");
Q; H6 F8 N( r5 \, h T& I& [0 `* X3 r0 I" ?
m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
% U0 |& b4 [+ P) w0 { m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
& A- l- W! h+ x% J m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");" K- Z$ N2 D1 G$ p$ D5 Y9 n
m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");5 ~$ H# U2 Q, A
m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");
R4 S* A6 S9 k, Q' d* @2 K8 w( ^% A# i! J
std::vector<NXOpen::Face *> boundaryFaces2(0);; i$ y' R# {$ b
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);+ b4 {# [& U+ O. p: D
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
8 e2 o% M/ t" i0 a. v/ i rules2[0] = faceTangentRule2;5 U" \3 g: o5 V/ L/ ^' J
m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);
g0 F" k7 `) I0 D3 x& k5 R% L8 q
8 O( n+ Z% g" ^, f$ [! x; V0 \ m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);7 U, t: j1 k, U2 d: N$ ?7 M4 F: [6 E6 U
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);4 A" P* q `# z- |
CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
- Q0 d; [) T, I& `- ~1 I NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));( Y/ V+ P4 P; I9 H$ H. T
NXOpen::Curve *nullNXOpen_Curve(NULL);5 }, u- m% k4 u. P0 r3 O
std::vector<NXOpen::SelectionIntentRule *> rules(1);5 J k0 m0 L8 u( S8 ^
rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05); S& I) \" V) n' A8 M
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
; ~6 J0 z7 o! w5 \- ^ NXOpen::NXObject *nullNXOpen_NXObject(NULL);
3 i8 H+ L1 f3 F& L' u" g& D NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);
) P; o6 J- {' N1 N/ V m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
1 q3 R3 O9 b- [! } NXOpen::Section::ModeCreate, false);
. U: v- A: B" b5 \5 x) e& @: o+ u5 Q1 A6 L7 G" m
if (bools)
K @3 T6 |6 P. T9 X {
+ z: m3 k& v! `: Y
" w; A% k( L% S if (m_pTextBuilder->Validate()): H6 Y. z2 w+ s. C- Q6 A
{, U4 P, O$ C9 T2 ~
m_pTextObject = m_pTextBuilder->Commit();" i2 Y* @& x t" X) v1 |
m_pTextBuilder->Destroy();/ L9 P7 P8 B2 c# y
m_pTextBuilder = NULL;
7 G6 v& e- y( T) c ^, [; l. r changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
% s1 k- |: d, p9 N$ \$ u. o changeStringContent->SetSensitivity(false);
3 ^+ p' X4 d0 F* y changeRealScale->SetSensitivity(false);0 T. e/ Y3 o2 l) y2 `
}
: `$ }0 }- D; H1 Q# X
3 X2 \/ E) \3 p }
7 [) m2 x9 `/ P else
# x5 I% C4 F4 x/ q) a {
' g, k: E0 J. D! b- v7 |( J: H //
% J$ g, W8 ]6 ~" H; A: J6 ` if (m_pTextBuilder->Validate())
' U& f) [6 [/ d' ^& X$ p {) F. v A6 ^8 z: i
m_pTextBuilder->Commit();
6 f% ] e! D7 n/ C UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);0 g0 }3 o) {3 i- j0 {9 d G2 s
m_pTextBuilder->Destroy();
( V, [/ X; o4 J m_pTextBuilder = NULL;( B- }& W! X6 ~
}% S, [7 y" z1 L3 r5 |7 z6 n
}
# I' G- l" I* i; @6 y
9 Y7 `$ v; `. r6 i7 b}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!
( ]/ J9 F$ `/ f3 Z4 U2 M |
|