From c20ff10e026de9393cedebf1afe2ecfda2bbb562 Mon Sep 17 00:00:00 2001 From: JackLee <809262979@qq.com> Date: Sun, 29 Mar 2026 22:26:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AD=97=E4=BD=93=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp | 6 +++- .../cpp/NativeEGLOCCT/Context/Context.cpp | 4 +-- .../main/cpp/NativeEGLOCCT/NativeRender.cpp | 19 ++++++++-- .../src/main/cpp/NativeEGLOCCT/NativeRender.h | 1 + .../cpp/NativeEGLOCCT/NativeRenderThread.cpp | 36 ++++++++++++++++++- .../cpp/NativeEGLOCCT/TextStyle/TextStyle.cpp | 4 +-- .../src/main/cpp/NativeEGLOCCT/View/View.cpp | 19 ++++++---- 7 files changed, 74 insertions(+), 15 deletions(-) diff --git a/entry/src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp b/entry/src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp index 57fb7236..417de55f 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/Axis/Axis.cpp @@ -85,8 +85,12 @@ bool Axis::InitAxisCube(Handle(AIS_InteractiveContext) & context,Handle(Prs3d_Te axiViewCube->SetTransparency(0.0); axiViewCube->SetFixedAnimationLoop(true); axiViewCube->SetTextColor(Quantity_Color(Quantity_NOC_YELLOW2)); - axiViewCube->SetFontHeight(35); + axiViewCube->SetFontHeight(30); + axiViewCube->SetFont("HarmonyOS Sans"); axiViewCube->SetMaterial(Graphic3d_MaterialAspect(Graphic3d_NOM_ALUMINIUM)); + axiViewCube->BoxEdgeStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont()); + axiViewCube->BoxCornerStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont()); + axiViewCube->BoxSideStyle()->Aspect()->SetTextFont(_textStyle->Aspect()->TextFont()); axiViewCube->SetTransformPersistence( new Graphic3d_TransformPers(Graphic3d_TMF_TriedronPers, Aspect_TOTP_RIGHT_UPPER, NCollection_Vec2(125, 125))); context->Display(axiViewCube, true); diff --git a/entry/src/main/cpp/NativeEGLOCCT/Context/Context.cpp b/entry/src/main/cpp/NativeEGLOCCT/Context/Context.cpp index 16036c54..2c090225 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/Context/Context.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/Context/Context.cpp @@ -18,8 +18,8 @@ bool Context::InitContext(Handle(V3d_Viewer)& viewer,Handle(Prs3d_TextAspect) _t try { context = new AIS_InteractiveContext(viewer); context->SetDisplayMode(AIS_Shaded, true); // 默认使用着色模式 - Handle(Prs3d_Drawer) theDrawer=context->DefaultDrawer(); - theDrawer->SetTextAspect(_textAspect); + //Handle(Prs3d_Drawer) theDrawer=context->DefaultDrawer(); + //theDrawer->SetTextAspect(_textAspect); HILOG_INFO(NATIVE_TAG, "InitCtx Done"); return true; } catch (std::exception &e) { diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp index cfb6e6f8..77ced906 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.cpp @@ -11,7 +11,7 @@ static std::mutex renderMutex; namespace NativeOpenCAX { NativeRender::NativeRender(int w, int h) - : width(0), height(0), mAxis(new Axis), nAxis(new Axis), cr(new Camera), ctx(new Context), + : width(0), height(0), mAxis(new Axis),nAxis(new Axis), cr(new Camera), ctx(new Context), ogd(new OpenGlGraphicDriver), ts(new TextStyle), vw(new View), vr(new Viewer), win(new Window) { width = w; height = h; @@ -64,6 +64,7 @@ bool NativeRender::init(EGLCore &_eglCore) { HILOG_ERROR(NATIVE_TAG, "Init AXIS Cuba Fail!"); return false; } + //InitDevText(); vw->ResetView(); return true; } @@ -188,7 +189,19 @@ void NativeRender::setZoomLevel(float zoom) { } void NativeRender::setClearColor(float r, float g, float b, float a) { vw->SetClearColor(r, g, b, a); } void NativeRender::resetView() { vw->ResetView(); } -void NativeRender::SwitchView(std::string view) { - vw->SwitchView(view); +void NativeRender::SwitchView(std::string str) { + vw->SwitchView(str); + +} +void NativeRender::InitDevText(){ + Handle(AIS_TextLabel) aTextLabel = new AIS_TextLabel(); + const char16_t chinese_array[] = u"新时代社会主义中国接班人"; + aTextLabel->SetText(chinese_array); + aTextLabel->Attributes()->SetTextAspect(ts->GetFontStyle(STYLE_AXIS)); + gp_Pnt position(0-(width/3), 0-(height/3), 0.0); // 例如,在原点 + aTextLabel->SetPosition(position); + ctx->context->Display(aTextLabel, Standard_True); + HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->FontName().ToCString()); + HILOG_ERROR(NATIVE_TAG, "aTextLabel字体名字:%{public}s", aTextLabel->Attributes()->TextAspect()->Aspect()->Font().ToCString()); } } // namespace NativeOpenCAX \ No newline at end of file diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h index 3207ff86..aee12f09 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRender.h @@ -51,6 +51,7 @@ public: void setCameraRotationMode(bool state); //视图 void SwitchView(std::string); + void InitDevText(); private: int width; int height; diff --git a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp index 748ba54d..a82e6261 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/NativeRenderThread.cpp @@ -56,7 +56,41 @@ void NativeRenderThread::renderLoop() { if (!eglCore_->init(nativeWindow_)) { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "EGLCoreInit","Failed to initialize EGL"); } - ftMgr=Font_FontMgr::GetInstance(); + ftMgr=Font_FontMgr::GetInstance(); + ftMgr->InitFontDataBase(); + ftMgr->SetPrintErrors(true); + ftMgr->SetTraceAliases(true); + Handle(Font_SystemFont) sysFont=new Font_SystemFont("HarmonyOS_Sans_Medium"); + sysFont->SetFontPath(Font_FontAspect_Regular, "/data/storage/el2/base/haps/entry/files/fonts/"); + // 注册字体。第二个参数如果是 Standard_True,表示强制注册,即使同名也覆盖。 + bool isRegistered = ftMgr->RegisterFont(sysFont, Standard_True); + + if (!isRegistered) { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","Error: Cannot register font: %{public}s",sysFont->FontName().ToCString()); + return; // 或者进行错误处理 + } else { + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","Successfully registered font: %{public}s",sysFont->FontName().ToCString()); + } + + Handle(Font_SystemFont) fsf; + fsf=ftMgr->GetFont("HarmonyOS_Sans_Medium"); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Path: %{public}s", fsf->FontPath(Font_FontAspect_Regular).ToCString()); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT GetFont: %{public}s", fsf->FontName().ToCString()); + //输出所有字体 + NCollection_Sequence> theAliases; + ftMgr->GetAllAliases(theAliases); + for(auto ft:theAliases){ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Aliases: %{public}s", ft->ToCString()); + } + //checkfont + NCollection_List> fsfs; + fsfs=ftMgr->GetAvailableFonts(); + for(auto fta:fsfs){ + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Font: %{public}s", fta->FontName().ToCString()); + OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "OCCT","OCCT Font Path: %{public}s", fta->FontPath(Font_FontAspect_Regular).ToCString()); + } + + // 初始化OCCT渲染器 if (!renderer_->init(*eglCore_)) { OH_LOG_Print(LOG_APP, LOG_ERROR, LOG_PRINT_DOMAIN, "NativeRenderInit","Failed to initialize OCCT renderer"); diff --git a/entry/src/main/cpp/NativeEGLOCCT/TextStyle/TextStyle.cpp b/entry/src/main/cpp/NativeEGLOCCT/TextStyle/TextStyle.cpp index f0423c54..e064ace1 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/TextStyle/TextStyle.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/TextStyle/TextStyle.cpp @@ -38,13 +38,13 @@ void TextStyle::InitAxisText(){ FONT_STYLE_TYPE styleType=FONT_STYLE_TYPE::STYLE_AXIS; Handle(Prs3d_TextAspect) axisText= new Prs3d_TextAspect(); axisText = new Prs3d_TextAspect(); - axisText->SetHeight(70); + axisText->SetHeight(50); axisText->SetFont("HarmonyOS Sans"); axisText->Aspect()->SetFont("HarmonyOS Sans"); axisText->Aspect()->SetColor(Quantity_NOC_GRAY95); axisText->Aspect()->SetColorSubTitle(Quantity_NOC_BLACK); axisText->Aspect()->SetDisplayType(Aspect_TODT_SHADOW); - axisText->Aspect()->SetTextFontAspect(Font_FA_Regular); + axisText->Aspect()->SetTextFontAspect(Font_FA_Bold); axisText->Aspect()->SetTextZoomable(false); axisText->SetHorizontalJustification(Graphic3d_HTA_LEFT); axisText->SetVerticalJustification(Graphic3d_VTA_BOTTOM); diff --git a/entry/src/main/cpp/NativeEGLOCCT/View/View.cpp b/entry/src/main/cpp/NativeEGLOCCT/View/View.cpp index e49fc9b6..e9340c7a 100644 --- a/entry/src/main/cpp/NativeEGLOCCT/View/View.cpp +++ b/entry/src/main/cpp/NativeEGLOCCT/View/View.cpp @@ -34,19 +34,27 @@ void View::SetViewOption(Handle(Prs3d_TextAspect) _textStyle) { view->ChangeRenderingParams().Method = Graphic3d_RM_RASTERIZATION; view->ChangeRenderingParams().IsShadowEnabled = Standard_False; view->ChangeRenderingParams().IsReflectionEnabled = Standard_False; + //抗锯齿开启后字体无法显示 // view->ChangeRenderingParams().IsAntialiasingEnabled = Standard_True; // view->ChangeRenderingParams().Resolution = 2; // 设置背景渐变 view->SetBgGradientColors(Quantity_Color(Quantity_NOC_GRAY), Quantity_Color(Quantity_NOC_BLACK), Aspect_GFM_VER, // 垂直渐变 false); + // 设置默认相机位置 view->SetProj(V3d_XposYnegZpos); - view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Orthographic); + view->FitAll(0.05, false); + // 可选:显示坐标轴 + view->ZBufferTriedronSetup(); + // 调整相机视角 + view->Camera()->SetProjectionType(Graphic3d_Camera::Projection_Perspective); view->SetBackgroundColor(Quantity_NOC_GRAY90); + //左下角默认坐标系 view->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_ANTIQUEWHITE, 0.3, V3d_ZBUFFER); - view->Trihedron(false)->LabelAspect(V3d_Y)->SetAspect(_textStyle->Aspect()); - view->Trihedron(false)->LabelAspect(V3d_X)->SetAspect(_textStyle->Aspect()); - view->Trihedron(false)->LabelAspect(V3d_Z)->SetAspect(_textStyle->Aspect()); + +// view->Trihedron(false)->LabelAspect(V3d_Y)->SetAspect(_textStyle->Aspect()); +// view->Trihedron(false)->LabelAspect(V3d_X)->SetAspect(_textStyle->Aspect()); +// view->Trihedron(false)->LabelAspect(V3d_Z)->SetAspect(_textStyle->Aspect()); view->SetBackgroundColor(Quantity_NOC_GRAY90); } @@ -71,8 +79,7 @@ void View::Redraw() { void View::ResetView() { if (!view.IsNull()) { view->SetProj(V3d_XposYnegZpos); - //view->FitAll(0.05, false); - view->AutoZFit(); + view->FitAll(0.05, false); } }