------------------------------------------------------------------------------
| 1106 | |
| 1107 | //------------------------------------------------------------------------------ |
| 1108 | bool vtkFreeTypeTools::RenderStringInternal( |
| 1109 | vtkTextProperty* tprop, const std::string& str, int dpi, vtkImageData* data, int textDims[2]) |
| 1110 | { |
| 1111 | // Check parameters |
| 1112 | if (!tprop || !data) |
| 1113 | { |
| 1114 | vtkErrorMacro(<< "Wrong parameters, one of them is nullptr or zero"); |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
| 1118 | if (data->GetNumberOfScalarComponents() > 4) |
| 1119 | { |
| 1120 | vtkErrorMacro("The image data must have a maximum of four components"); |
| 1121 | return false; |
| 1122 | } |
| 1123 | |
| 1124 | if (str.empty()) |
| 1125 | { |
| 1126 | data->Initialize(); |
| 1127 | if (textDims) |
| 1128 | { |
| 1129 | textDims[0] = 0; |
| 1130 | textDims[1] = 0; |
| 1131 | } |
| 1132 | return true; |
| 1133 | } |
| 1134 | |
| 1135 | ImageMetaData metaData; |
| 1136 | |
| 1137 | // Setup the metadata cache |
| 1138 | if (!this->PrepareMetaData(tprop, dpi, metaData)) |
| 1139 | { |
| 1140 | vtkErrorMacro(<< "Error prepare text metadata."); |
| 1141 | return false; |
| 1142 | } |
| 1143 | |
| 1144 | // Calculate the bounding box. |
| 1145 | if (!this->CalculateBoundingBox(str, metaData)) |
| 1146 | { |
| 1147 | vtkErrorMacro(<< "Could not get a valid bounding box."); |
| 1148 | return false; |
| 1149 | } |
| 1150 | |
| 1151 | // Calculate the text dimensions: |
| 1152 | if (textDims) |
| 1153 | { |
| 1154 | textDims[0] = metaData.bbox[1] - metaData.bbox[0] + 1; |
| 1155 | textDims[1] = metaData.bbox[3] - metaData.bbox[2] + 1; |
| 1156 | } |
| 1157 | |
| 1158 | // Prepare the ImageData to receive the text |
| 1159 | this->PrepareImageData(data, metaData.bbox.GetData()); |
| 1160 | |
| 1161 | // Setup the image metadata |
| 1162 | if (!this->PrepareImageMetaData(tprop, data, metaData)) |
| 1163 | { |
| 1164 | vtkErrorMacro(<< "Error prepare image metadata."); |
| 1165 | return false; |
no test coverage detected