MCPcopy Create free account
hub / github.com/Kitware/VTK / ComputeFontSizeForBoundedString

Method ComputeFontSizeForBoundedString

Rendering/Context2D/vtkContext2D.cxx:700–741  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

698
699//------------------------------------------------------------------------------
700int vtkContext2D::ComputeFontSizeForBoundedString(
701 const vtkStdString& string, float width, float height)
702{
703 double orientation = this->GetTextProp()->GetOrientation();
704 this->GetTextProp()->SetOrientation(0.0);
705
706 float stringBounds[4];
707 int currentFontSize = this->GetTextProp()->GetFontSize();
708 this->ComputeStringBounds(string, stringBounds);
709
710 // font size is too big
711 if (stringBounds[2] > width || stringBounds[3] > height)
712 {
713 while (stringBounds[2] > width || stringBounds[3] > height)
714 {
715 --currentFontSize;
716 this->GetTextProp()->SetFontSize(currentFontSize);
717 this->ComputeStringBounds(string, stringBounds);
718 if (currentFontSize < 0)
719 {
720 this->GetTextProp()->SetFontSize(0);
721 return 0;
722 }
723 }
724 }
725
726 // font size is too small
727 else
728 {
729 while (stringBounds[2] < width && stringBounds[3] < height)
730 {
731 ++currentFontSize;
732 this->GetTextProp()->SetFontSize(currentFontSize);
733 this->ComputeStringBounds(string, stringBounds);
734 }
735 --currentFontSize;
736 this->GetTextProp()->SetFontSize(currentFontSize);
737 }
738
739 this->GetTextProp()->SetOrientation(orientation);
740 return currentFontSize;
741}
742
743//------------------------------------------------------------------------------
744void vtkContext2D::DrawMathTextString(vtkPoints2D* point, const vtkStdString& string)

Callers 5

PaintBuffersMethod · 0.80
ComputeLabelWidthMethod · 0.80
PaintBuffersMethod · 0.80
ComputeLabelWidthMethod · 0.80

Calls 5

GetTextPropMethod · 0.95
ComputeStringBoundsMethod · 0.95
SetFontSizeMethod · 0.80
GetOrientationMethod · 0.45
SetOrientationMethod · 0.45

Tested by

no test coverage detected