|
|
请使用QQ关联注册PLM之家,学习更多关于内容,更多精彩原创视频供你学习!
您需要 登录 才可以下载或查看,没有账号?注册
x
我是新人 想用TextBuilder辅助实现刻字功能,附上我自己克隆journal 的字体处理代码,还在修改中:
7 W2 X. S p% h' q
4 d: n4 g9 q! e' F5 f) V% h1 qvoid Letter::textProcess(const char * fonTContent, char* fontType, double& wScale,bool bools)
2 p4 y4 a. a! C( r6 ?{
) I0 m1 m0 f0 I) r$ H( ? if (m_pTextBuilder == NULL)
' {+ V% x2 h. n7 C5 Q" G1 p& [7 y& ]* ^) X m_pTextBuilder = m_pTextBuilder = workPart->Features()->CreateTextBuilder(m_pNullNXOpen_Features_Texts);
6 G! M! ~" F) U6 K y' u- \* o1 F+ i f int i = 0;: D+ _" C) S2 M2 @# a! H% Z" k( |
+ o$ e& ]" C' y& U2 f m_pTextBuilder->SetFontStyle(NXOpen::Features::TextBuilder::FontStyleOptions::FontStyleOptionsRegular);. ?) M- c! `$ Y8 M: [+ |
m_pTextBuilder->SetOrientationMethod(NXOpen::Features::TextBuilder::OrientationMethodOptions::OrientationMethodOptionsNatural);
8 R# {6 X" D3 r! G6 O+ N NXOpen::Features::TextBuilder::ScriptOptions characterSet;
U6 ?5 n# d3 N; g4 w if (fontType[1] >= 'A'&&fontType[1] <= 'z')
: I5 |- c) Q; ]3 |' Y characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsWestern;* d) b5 s5 N: P& {) J. \
else
5 y2 I$ E' ]0 t7 D% g. f characterSet = NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312;& ^7 G" C: h' d: j: ^8 u8 C
i = 0;$ t: X! v3 r7 X" L
while (1)
9 Z7 Q' m$ K& f$ Z; b# \( c0 `( p {
# p3 q3 l/ e0 j2 |) q) A if (fontContent == 0) break;
# j) A' y2 `. Z# |) t! s if (fontContent & 0x80)
6 Q* E0 p$ ? f0 q% \ if (fontContent[i + 1] & 0x80)
, w; r" G) P8 n* a& E5 [; ] if (characterSet != NXOpen::Features::TextBuilder::ScriptOptions::ScriptOptionsGb2312)
! D/ {5 v3 b- s6 d# x' t H {
1 Q7 h4 `+ K( W5 M uc1601("含有汉字,选择的字符集可能不支持汉字而导致系统提示出错!!!", 1);
~1 h8 g5 m/ f3 \! o- P& P break;* O& J, U: a: T0 Q
}
- u' n) w5 w) r1 ?* I i++;8 t2 t* x- W2 A U( Z6 @# Z
}
5 i; j4 [2 I7 q. Y: Y m_pTextBuilder->SetTextString(fontContent);
7 K* v* D5 x: A" q4 g' K m_pTextBuilder->SelectFont(fontType, characterSet);
4 v7 K& A9 ]' J* b5 V. z& m& f m_pTextBuilder->SetCanUseKerningSpaces(true);' c: I' L9 u7 {, W! v
m_pTextBuilder->SetCanReverseIntersectionCurve(true);
2 }3 M4 o; f4 f
2 ]- v- Y% R* e" X* S NXOpen: irection * orientationVector = workPart->Directions()->CreateDirection(Point3d(m_pnPoint[0], m_pnPoint[1], m_pnPoint[2]),5 |7 g$ s% s$ V7 i
Vector3d((m_pnPoint[0] - m_pnPoint[6]), (m_pnPoint[1] - m_pnPoint[7]), (m_pnPoint[2] - m_pnPoint[8])),* f7 K% ]6 @# Y9 M/ W5 p* g+ s! P
SmartObject::UpdateOption::UpdateOptionWithinModeling);( i; [+ s7 B* X; [# w$ l5 G& L
m_pTextBuilder->SetOrientationVector(orientationVector);
" ]) Q* K% k" _
1 c& K% f, L* J$ y8 u6 |; _ C { m_pTextBuilder->SetType(NXOpen::Features::TextBuilder::TypesOnFace);' l' B* j3 _! S, N: u
m_pTextBuilder-> lanarFrame()->SetAnchorLocation(NXOpen::GeometricUtilities::RectangularFrameBuilder::AnchorLocationTypeBottomCenter);
: [! b3 B" O, Q3 D' X& U- N9 w) b2 M0 ^8 ~- w
i = strlen(fontContent);
, }& _# w$ i: v: L7 K char buf[256] = { 0 };
% x9 ]% o3 Q6 g sprintf(buf, "%f", i * 10 * (wScale / 50.0));
7 \( F. v# J' D3 V2 F( M m_pTextBuilder-> lanarFrame()->Length()->SetRightHandSide(buf);7 @ j9 y4 a- p" r6 |- R
sprintf(buf, "%f", 10 * (wScale / 50.0));
1 q0 z5 b* J f/ z m_pTextBuilder-> lanarFrame()->Height()->SetRightHandSide(buf);. a9 v+ ]" N- [) A% q2 ]
m_pTextBuilder-> lanarFrame()->Shear()->SetRightHandSide("0");7 s2 M2 H/ u; p* {8 Z
6 \( s& C4 ~% z6 g m_pTextBuilder->FrameOnPath()->AnchorPosition()->SetParameterUsed(false);
( [% q6 m7 a% J; {! F m_pTextBuilder->FrameOnPath()->Offset()->SetRightHandSide("0");
) o; g/ G9 }3 X% ?1 f: \+ M3 f4 Q! l m_pTextBuilder->FrameOnPath()->Length()->SetRightHandSide("5.25771270972214");
5 K8 H, O; y# o m_pTextBuilder->FrameOnPath()->Height()->SetRightHandSide("3.1");
$ Z" I( v& P/ ~! v0 S: r m_pTextBuilder->FrameOnPath()->AnchorPosition()->Expression()->SetRightHandSide("50");8 w# \1 ]# T5 W3 b7 T4 @
4 B9 W/ v/ ~0 A v
std::vector<NXOpen::Face *> boundaryFaces2(0);/ ?# I. h$ ~( ~6 [8 B$ n) [0 [
NXOpen::FaceTangentRule *faceTangentRule2 = workPart->ScRuleFactory()->CreateRuleFaceTangent(m_pface, boundaryFaces2, 0.05);2 o! [% [6 v% _4 U
std::vector<NXOpen::SelectionIntentRule *> rules2(1);
$ n) j: h5 k( g7 b' M+ N rules2[0] = faceTangentRule2;
3 F2 P7 c0 C _- d m_pTextBuilder-> lacementFaces()->ReplaceRules(rules2, false);' E" @6 E; y2 M! e- e0 X2 h
/ m+ ?3 [; l+ `7 ^( F5 Y9 @' n- z5 O
m_pTextBuilder->OnFacePlacementProfile()->SetAllowedEntityTypes(NXOpen::Section::AllowTypesOnlyCurves);: B/ i/ F* b L4 `
std::vector<NXOpen::Features::Feature *> CurveOnSurfaceFeatures(1);
, p3 |0 p* A& ~$ J: w* d( B U CurveOnSurfaceFeatures[0] = dynamic_cast<NXOpen::Features::CurveOnSurface *>(m_pCurveOnSurfaceObject);
# X3 N; L1 g% O; n ^8 I NXOpen::Spline *spline1 = dynamic_cast<NXOpen::Spline *>(CurveOnSurfaceFeatures[0]->FindObject("CURVE 1"));
% @2 L& |* T. B }' h( \" d; H NXOpen::Curve *nullNXOpen_Curve(NULL);
5 z/ _9 W: f5 E1 D. U7 }) j std::vector<NXOpen::SelectionIntentRule *> rules(1);
3 U& R0 f2 Z5 z5 D rules[0] = workPart->ScRuleFactory()->CreateRuleCurveFeatureTangent(CurveOnSurfaceFeatures, spline1, nullNXOpen_Curve, false, 0.001, 0.05);8 ^. |# S* u- U. y
m_pTextBuilder->OnFacePlacementProfile()->AllowSelfIntersection(true);
- Q) f; D1 S6 a' o- w NXOpen::NXObject *nullNXOpen_NXObject(NULL);* S& v9 P5 V/ C a
NXOpen: oint3d helpPoint1(m_pnPoint[3], -m_pnPoint[4], m_pnPoint[5]);- f7 e" T& J+ l6 A$ i/ |( l3 Y
m_pTextBuilder->OnFacePlacementProfile()->AddToSection(rules, spline1, nullNXOpen_NXObject, nullNXOpen_NXObject, helpPoint1,
l6 j+ W+ p8 Z) h, K8 e NXOpen::Section::ModeCreate, false);
; l' \) |. P0 @* M, b5 @4 l$ A W+ L9 C. k4 A
if (bools)
! r- m# ^! c e* [/ ~& M {
* C0 F" [0 f# I* O$ u3 M! P
8 m6 {8 Z3 n& r/ D4 Y3 d if (m_pTextBuilder->Validate())
$ U# W% F/ ?& V- k {
2 [1 ~+ ?' I% h m_pTextObject = m_pTextBuilder->Commit();+ [) c* @5 O6 G1 T7 U4 ~
m_pTextBuilder->Destroy();& j8 X7 J6 T' P& I, [
m_pTextBuilder = NULL;
. N1 Q% q, |+ e5 @- g, ^1 [ changeFontType->SetSensitivity(UF_STYLER_NO_SUB_INDEX, false);
7 K* l# R' S( G9 {% X# x; v changeStringContent->SetSensitivity(false);: C0 d' u' o7 r
changeRealScale->SetSensitivity(false);4 v2 \% C1 |( s% b9 X4 A
}, N* x7 A" n# D5 [2 @
1 M) C* x3 I" I- Z }$ z( Y! y( c1 V* a& Q0 c
else) L* z% S4 C& l2 c0 T' H
{
, L' ]- [' F( T: l6 _) O) c // , ^9 A5 f# z1 t5 ~4 k/ o
if (m_pTextBuilder->Validate())0 t0 X" M- R2 m% m. l0 ~2 f6 x
{
# y' h7 n% j9 i) J' B& s# t m_pTextBuilder->Commit();: B4 u# T+ d- A$ J
UF_SO_set_visibility_option(m_pTextBuilder->Tag(), UF_SO_visible);
5 q* Y5 n$ l/ L; k6 X7 g' ^7 U m_pTextBuilder->Destroy();# ?4 G( m& E2 c4 H+ b& R: i
m_pTextBuilder = NULL;1 J9 O/ u+ x( B. t
}: q% @7 q# @. c2 \' G( B: A' ?; u
}
: V" A8 g) A5 t0 l2 i5 F0 S- r
& T. s5 p! [' X2 r% M; v}我想实现一个字体预览效果 ,望有空的前辈指导指点!!!!$ C/ B1 c! M% X% g# R6 h( W
|
|