From 78b89c976fd7bea7e1c7ccbe88ca2191b3b4abf7 Mon Sep 17 00:00:00 2001 From: Krad Date: Mon, 16 Jan 2023 13:40:19 +0800 Subject: [PATCH] Auto adjust corner annotation font size. --- .../Legend/FastCornerAnnotationActor.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp b/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp index e834ce6..f9ccd42 100644 --- a/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp +++ b/src/src/Rendering/Legend/FastCornerAnnotationActor.cpp @@ -21,7 +21,7 @@ FastCornerAnnotationActor::FastCornerAnnotationActor() Actors[i]->SetTextScaleModeToNone(); Actors[i]->SetUseBorderAlign(true); Actors[i]->GetTextProperty()->SetFontFamilyToCourier(); - Actors[i]->GetTextProperty()->SetFontSize(13); + Actors[i]->GetTextProperty()->SetFontSize(6); Actors[i]->GetTextProperty()->BoldOn(); Actors[i]->GetTextProperty()->ShadowOn(); Actors[i]->GetActualPositionCoordinate()->SetCoordinateSystemToDisplay(); @@ -107,9 +107,22 @@ vtkTypeBool FastCornerAnnotationActor::HasTranslucentPolygonalGeometry() { void FastCornerAnnotationActor::ResetTextPosition(vtkRenderer* renderer) { double x = 1.0, y = 1.0; renderer->NormalizedDisplayToDisplay(x, y); + + double width = renderer->GetSize()[0] + 0.5; + double height = renderer->GetSize()[1] + 0.5; + double newFontSize = 6.0; + //文字的宽一般是高的一半 + if (renderer->GetTiledAspectRatio()>0.5){ + newFontSize = (width / 300) + 10.0; + } + else{ + newFontSize = (height / 200) + 10.0; + } + newFontSize = newFontSize > 16 ? 16 : (newFontSize < 10 ? 10 : newFontSize); for (int i = 0; i < 8; ++i) { Actors[i]->GetActualPosition2Coordinate()->SetCoordinateSystemToDisplay(); Actors[i]->SetPosition2(x - 5,y - 5); + Actors[i]->GetTextProperty()->SetFontSize(newFontSize); } }