+ int tw = ceil(text->tw);
+ int th = ceil(text->th);
+
+ double rotate_rad = text->rotate / (-180 / M_PI);
+
+ // Initially, ll = [0; 0], lr = [tw, 0], ul = [0, th], ur = [tw, th]
+ // They could be declared before but should not be initialized in code
+ // as reassigning x-coordinate affects computation of y-cordinate
+ int llx = 0;
+ int lly = 0;
+
+ int lrx = tw * cos(rotate_rad);
+ int lry = tw * sin(rotate_rad);
+
+ int ulx = th * sin(rotate_rad);
+ int uly = th * cos(rotate_rad);
+
+ int urx = tw * cos(rotate_rad) + th * sin(rotate_rad);
+ int ury = tw * sin(rotate_rad) + th * cos(rotate_rad);
+
+ int min_x = min4(llx, lrx, ulx, urx);
+ int min_y = min4(lly, lry, uly, ury);
+ int max_x = max4(llx, lrx, ulx, urx);
+ int max_y = max4(lly, lry, uly, ury);
+
+ v->width = max_x - min_x + 1;
+ v->height = max_y - min_y + 1;