mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	hopefully this uses a reasonable y offset
This commit is contained in:
		
							parent
							
								
									25b39de5b7
								
							
						
					
					
						commit
						02855a86c0
					
				| 
						 | 
				
			
			@ -157,6 +157,9 @@ class FreeTypeFont:
 | 
			
		|||
    def getsize(self, text):
 | 
			
		||||
        return self.font.getsize(text)[0]
 | 
			
		||||
 | 
			
		||||
    def getoffset(self, text):
 | 
			
		||||
        return self.font.getsize(text)[1]
 | 
			
		||||
 | 
			
		||||
    def getmask(self, text, mode=""):
 | 
			
		||||
        return self.getmask2(text, mode)[0]
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +186,7 @@ class TransposedFont:
 | 
			
		|||
        self.orientation = orientation # any 'transpose' argument, or None
 | 
			
		||||
 | 
			
		||||
    def getsize(self, text):
 | 
			
		||||
        w, h = self.font.getsize(text)
 | 
			
		||||
        w, h = self.font.getsize(text)[0]
 | 
			
		||||
        if self.orientation in (Image.ROTATE_90, Image.ROTATE_270):
 | 
			
		||||
            return h, w
 | 
			
		||||
        return w, h
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										13
									
								
								_imagingft.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								_imagingft.c
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -183,7 +183,7 @@ font_getsize(FontObject* self, PyObject* args)
 | 
			
		|||
    int i, x, y_max, y_min;
 | 
			
		||||
    FT_ULong ch;
 | 
			
		||||
    FT_Face face;
 | 
			
		||||
    int xoffset;
 | 
			
		||||
    int xoffset, yoffset;
 | 
			
		||||
    FT_Bool kerning = FT_HAS_KERNING(self->face);
 | 
			
		||||
    FT_UInt last_index = 0;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -203,7 +203,7 @@ font_getsize(FontObject* self, PyObject* args)
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    face = NULL;
 | 
			
		||||
    xoffset = 0;
 | 
			
		||||
    xoffset = yoffset = 0;
 | 
			
		||||
    y_max = y_min = 0;
 | 
			
		||||
 | 
			
		||||
    for (x = i = 0; font_getchar(string, i, &ch); i++) {
 | 
			
		||||
| 
						 | 
				
			
			@ -232,6 +232,10 @@ font_getsize(FontObject* self, PyObject* args)
 | 
			
		|||
        if (bbox.yMin < y_min)
 | 
			
		||||
            y_min = bbox.yMin;
 | 
			
		||||
            
 | 
			
		||||
        /* find max distance of baseline from top */
 | 
			
		||||
        if (face->glyph->metrics.horiBearingY > yoffset)
 | 
			
		||||
            yoffset = face->glyph->metrics.horiBearingY;
 | 
			
		||||
            
 | 
			
		||||
        last_index = index;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -248,12 +252,15 @@ font_getsize(FontObject* self, PyObject* args)
 | 
			
		|||
            face->glyph->metrics.horiBearingX;
 | 
			
		||||
        if (offset < 0)
 | 
			
		||||
            x -= offset;
 | 
			
		||||
        /* difference between the font ascender and the distance of
 | 
			
		||||
         * the baseline from the top */
 | 
			
		||||
        yoffset = PIXEL(self->face->size->metrics.ascender - yoffset);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return Py_BuildValue(
 | 
			
		||||
        "(ii)(ii)",
 | 
			
		||||
        PIXEL(x), PIXEL(y_max - y_min),
 | 
			
		||||
        PIXEL(xoffset), 0
 | 
			
		||||
        PIXEL(xoffset), yoffset
 | 
			
		||||
        );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user