From dea30e4c807f76931d5b37736c6be2dd2f8546b2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 18 Jul 2022 08:39:23 +1000 Subject: [PATCH] Fixed set_variation_by_name offset --- Tests/images/variation_adobe_name.png | Bin 1431 -> 1475 bytes .../variation_adobe_older_harfbuzz_name.png | Bin 1432 -> 1492 bytes Tests/test_imagefont.py | 4 +++- src/PIL/ImageFont.py | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Tests/images/variation_adobe_name.png b/Tests/images/variation_adobe_name.png index 11ceaf6e65b60a9a9fafacf1d72f8bc8227d8e1c..5168e04b99bc16ea9ba6c57f3a7d4ec3cf3a47ad 100644 GIT binary patch literal 1475 zcmb7^c`zFY6voq*MN-ukS@fW2CsLxNHB+QkBuEe>wvN@r5yq%V*R4@Ul!myf?s3$T zNKrkcCXS|5-PB0y3K3Tmwjq>pq;;&$?ChVrvwytzX5M`BX5P&A{nA{pcFI64AOHYR zM%yEChm&+z4vI$)yAq{w766c^qmkBbF{LZT4v_n<8ttp+{Hxz+*#`AK>gn*;dvOJo zm#1rD0O~@ld-P_wBkVE!j1*iR1k_Mz3G}xH2l_6+@x9j&4}$^+_l(KY(gVRA!D^P> zm)%DvSYV(bap0x2&^JXHYrwCR>mM; zzGz`#kC##7 z>W@$Am&*UteEg;oj$R zbuhS~wAAq=($@CjT4h>VTEs064-Jz5&QzxDf=I-iCab8ZWM^i67#PUK_|BM?{{aaO z30Ve#_T9bY1mDn;Oe8*O zGQz8Es?u<@_q?&Og0eF1>(`&dnn@;}cka}^^MOF2x{C8+adll?9fR>%BuYVRYHJ%C z8Hwu6%*`=v8d_TYgM*}Q1qFqbsMY}yolc(*lzsnRHyYgNRqq1nTt$}plgqN78?rum z5(qEHI&q}D&Bl?3u*BXwI z@80FJ(P*?lH!?EPK4*B?h4PZk{#5d}@XVHSk$8DIqdcs2dVG95HMOEbhn&;eY9ZD( zFe@%D#rv6c}$YierjCj^4hRMB8yxV^n%v}+2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ZEd7Z(i-N_u0< z5h<|xwKg2zls4>dn@J|$OiF{u5^*HbN!I-IbZN!pg`A)ukj=*WdUsvInKR|=7LkZ; z>1|2R&d%22jEscL(;t*3#Gh-&*&9t?Y;A4DX`@i6TrWSr1@P|9&O5pM^s(#6J6!Hz z+Aty@n2?bnmsqyBle1iPm-B#Dwcqh$p`EHfKTVdEsk6`(ilyac z#pF!C%i-haE9DH^+5-%vc*84V%~frlnxO0WOX= zWMc?UXH!!XkP86R-Ca{f&Ci!gr7OmHWO4(G73}z8WyK-zJQjQPEU*V%erZUgx(z8e zw;38&J?7=^o^rw>u0x{AY{Bt0fA|3yRWKMlU2u=j2gWEgH1w4C93H>F%gjwqw%@a{ zwz6_{b8F=SEdVpCbfTi7T$thfH7u{2&%aEi){U>df8RB*J2N}0rlxiPk!t`?7ElWc zL~)+wQ+J=R6k25&j7RBFx_3c}jmzTP7+n`Zu zP;7K8Kg)4KY7Fd|a}rQTvfE*vlJT jR{ob3{XgXbqGg8g-roW;Vn=-e!3Cj$(a7Hs$yfgYM*NXQ diff --git a/Tests/images/variation_adobe_older_harfbuzz_name.png b/Tests/images/variation_adobe_older_harfbuzz_name.png index 2adb517a759aab4a06e83cc7ab604f97f88c1d27..fa0e307b4f650e007f30bd2ede877c8fd6843116 100644 GIT binary patch literal 1492 zcmb7E`7_%I6pwQWafhNUDvoNjsWh zI~W5%bCQz;y*#~+4}r)OI$~|F(29ilP7b=h8n;#vrzOZnq4$jLv&Wm(*vHSprzA3D zRMYOa>o=H=GVWzDf-B&saZakzs2c`yP|{4hY*jdE7xmlvUQUD`&9b*e5xNEkUGR8iF&dy!>n**a zR=sdITt(T#n#i`~GzNoFyEkt_0303D_gGvm_Y%F)Qd3j&gS&lIMKg7^@6;~7cSDpg z+nS7bD%1EInb&*8&o5JjzQ(`3$0{i)82}MP!9}-+yp{cZF$(7<5{amPO~>u+uV3vUc#?Qq$mKG&%sK}1Vl2^UA9r^aP;O-Q zTV`fTY+~Zw55ZQGJRZT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yTJ`# z%CPnZiwWDiyPZ6<@mu`7JguTZ*~W%02$UrP8yU6Ke&vWZ7I!ZK;|4rlu-^Vs8?OL?zl^U^8Q5I`GKI$h?CiBO_3TfsxVK z)5`JsYZKA-XZ-zF6J5e+8biUh)QpS_2m~S&3g4Tzw6v6$m&e4!M2${QPCnbkxIm%f z5?3cUJo5Z`q}8}cbW~5x7V72(DH$HMRmtQk1wp5OZ(G~dH7i*i9vV{9)I_R`Ih#bY z6$(XTBaJ&GV=x#>?sxntl%Ba_8cq5C4}Xv+rC7QdXzZt->BBTh3rb2vQmK8M5ZXvM zC%K;JGTqnLH#b)q+_03;hG`11rOxMP=PCUHmz4DN2?Wczym^@{aqZ(imQ5q8o8BO^Ic=frZ diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index 16da87d469a..4c48d4ef3f4 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -769,12 +769,14 @@ def test_variation_set_by_name(self): self._check_text(font, "Tests/images/variation_adobe.png", 11) for name in ["Bold", b"Bold"]: font.set_variation_by_name(name) - self._check_text(font, "Tests/images/variation_adobe_name.png", 11) + assert font.getname()[1] == "Bold" + self._check_text(font, "Tests/images/variation_adobe_name.png", 16) font = ImageFont.truetype("Tests/fonts/TINY5x3GX.ttf", 36) self._check_text(font, "Tests/images/variation_tiny.png", 40) for name in ["200", b"200"]: font.set_variation_by_name(name) + assert font.getname()[1] == "200" self._check_text(font, "Tests/images/variation_tiny_name.png", 40) def test_variation_set_by_axes(self): diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index a3b711c6077..9a12ba48d2b 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -795,7 +795,7 @@ def set_variation_by_name(self, name): names = self.get_variation_names() if not isinstance(name, bytes): name = name.encode() - index = names.index(name) + index = names.index(name) + 1 if index == getattr(self, "_last_variation_index", None): # When the same name is set twice in a row,