762 |
762 |
763 "if I am already assigned to that device ..." |
763 "if I am already assigned to that device ..." |
764 (device == aGraphicsDevice) ifTrue:[^ self]. |
764 (device == aGraphicsDevice) ifTrue:[^ self]. |
765 |
765 |
766 (aGraphicsDevice isNil and:[device notNil]) ifTrue:[ |
766 (aGraphicsDevice isNil and:[device notNil]) ifTrue:[ |
767 ^ self |
767 ^ self |
|
768 ]. |
|
769 aGraphicsDevice supportsXFTFonts ifFalse:[ |
|
770 ^ super onDevice:aGraphicsDevice |
768 ]. |
771 ]. |
769 |
772 |
770 (closestFont notNil and:[closestFont graphicsDevice == aGraphicsDevice]) ifTrue:[ |
773 (closestFont notNil and:[closestFont graphicsDevice == aGraphicsDevice]) ifTrue:[ |
771 ^ closestFont onDevice: aGraphicsDevice. |
774 ^ closestFont onDevice: aGraphicsDevice. |
772 ]. |
775 ]. |
773 |
776 |
774 RecentlyUsedFonts isNil ifTrue:[ |
777 RecentlyUsedFonts isNil ifTrue:[ |
775 RecentlyUsedFonts := OrderedCollection new:10. |
778 RecentlyUsedFonts := OrderedCollection new:10. |
776 ]. |
779 ]. |
777 |
780 |
778 RecentlyUsedFonts keysAndValuesDo:[:index :aFont | |
781 RecentlyUsedFonts keysAndValuesDo:[:index :aFont | |
779 ((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getFontId notNil]]) ifTrue:[ |
782 ((aFont class == self class) and:[(self sameDeviceFontAs:aFont) and:[aFont getFontId notNil]]) ifTrue:[ |
780 "/ Transcript showCR:'hit'. |
783 "/ Transcript showCR:'hit'. |
781 RecentlyUsedFonts removeIndex:index. |
784 RecentlyUsedFonts removeIndex:index. |
782 RecentlyUsedFonts addFirst:aFont. |
785 RecentlyUsedFonts addFirst:aFont. |
783 ^ aFont |
786 ^ aFont |
784 ] |
787 ] |
785 ]. |
788 ]. |
786 |
789 |
787 RecentlyUsedFonts size > 20 ifTrue:[ |
790 RecentlyUsedFonts size > 20 ifTrue:[ |
788 RecentlyUsedFonts removeLast. |
791 RecentlyUsedFonts removeLast. |
789 ]. |
792 ]. |
790 |
793 |
791 aGraphicsDevice deviceFonts do:[:aFont | |
794 aGraphicsDevice deviceFonts do:[:aFont | |
792 ((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[ |
795 ((aFont class == self class) and:[self sameDeviceFontAs:aFont]) ifTrue:[ |
793 RecentlyUsedFonts addFirst:aFont. |
796 RecentlyUsedFonts addFirst:aFont. |
794 ^ aFont |
797 ^ aFont |
795 ]. |
798 ]. |
796 ]. |
799 ]. |
797 |
800 |
798 [ |
801 [ |
799 myPatternId := self xftPatternCreate. |
802 myPatternId := self xftPatternCreate. |
800 self xftPatternAdd: myPatternId attribute: FC_FAMILY value: family. |
803 self xftPatternAdd: myPatternId attribute: FC_FAMILY value: family. |
801 pixelSize notNil ifTrue:[ |
804 pixelSize notNil ifTrue:[ |
802 self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: pixelSize. |
805 self xftPatternAdd: myPatternId attribute: FC_PIXEL_SIZE value: pixelSize. |
803 ] ifFalse:[ |
806 ] ifFalse:[ |
804 self xftPatternAdd: myPatternId attribute: FC_SIZE value: size. |
807 self xftPatternAdd: myPatternId attribute: FC_SIZE value: size. |
805 ]. |
808 ]. |
806 self xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular')). |
809 self xftPatternAdd: myPatternId attribute: FC_WEIGHT value: (StXFace2FCWeightMap at: (face ? 'regular')). |
807 self xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]). |
810 self xftPatternAdd: myPatternId attribute: FC_SLANT value: (StXStyle2FCSlantMap at: (style ? 'roman') ifAbsent:[StXStyle2FCSlantMap at: (style ? 'roman') asLowercase]). |
808 |
811 |
809 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId. |
812 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: myPatternId. |
810 newFontId notNil ifTrue:[ |
813 newFontId notNil ifTrue:[ |
811 "/ Good, this font exists!! |
814 "/ Good, this font exists!! |
812 fontId := newFontId. |
815 fontId := newFontId. |
813 device := aGraphicsDevice. |
816 device := aGraphicsDevice. |
814 aGraphicsDevice registerFont:self. |
817 aGraphicsDevice registerFont:self. |
815 RecentlyUsedFonts addFirst:self. |
818 RecentlyUsedFonts addFirst:self. |
816 ^ self. |
819 ^ self. |
817 ] ifFalse:[ |
820 ] ifFalse:[ |
818 closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId. |
821 closestPatternId1 := self xftFontMatch: aGraphicsDevice displayId screen: aGraphicsDevice screen pattern: myPatternId. |
819 closestPatternId1 isNil ifTrue:[ |
822 closestPatternId1 isNil ifTrue:[ |
820 self error: 'No font matches'. |
823 self error: 'No font matches'. |
821 ]. |
824 ]. |
822 " |
825 " |
823 self xftPatternGet: closestPatternId attribute: 'family' index: 0. |
826 self xftPatternGet: closestPatternId attribute: 'family' index: 0. |
824 self xftPatternGet: closestPatternId attribute: 'size' index: 0. |
827 self xftPatternGet: closestPatternId attribute: 'size' index: 0. |
825 " |
828 " |
826 closestPatternId2 := self xftPatternDuplicate: closestPatternId1. |
829 closestPatternId2 := self xftPatternDuplicate: closestPatternId1. |
827 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1. |
830 newFontId := self xftFontOpenPattern: aGraphicsDevice displayId pattern: closestPatternId1. |
828 "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!! |
831 "/ !!!!!!!! closestPatternId is no longer valid !!!!!!!! |
829 closestPatternId1 := nil. |
832 closestPatternId1 := nil. |
830 newFontId isNil ifTrue:[ |
833 newFontId isNil ifTrue:[ |
831 self error: 'Pattern matched, but font could not be opened (should not happen)'. |
834 self error: 'Pattern matched, but font could not be opened (should not happen)'. |
832 ]. |
835 ]. |
833 |
836 |
834 "/ Search for existing registered font. Note, that XftFont instances |
837 "/ Search for existing registered font. Note, that XftFont instances |
835 "/ are shared (and refcounted) so newFontId = aFont getFontId is enough |
838 "/ are shared (and refcounted) so newFontId = aFont getFontId is enough |
836 "/ to check whether some other font instance represents the same font... |
839 "/ to check whether some other font instance represents the same font... |
837 aGraphicsDevice deviceFonts do:[:aFont | |
840 aGraphicsDevice deviceFonts do:[:aFont | |
838 ((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[ |
841 ((self class == aFont class) and:[newFontId = aFont getFontId]) ifTrue:[ |
839 closestFont := aFont. |
842 closestFont := aFont. |
840 ^ closestFont |
843 ^ closestFont |
841 ]. |
844 ]. |
842 ]. |
845 ]. |
843 |
846 |
844 closestFont := self shallowCopy |
847 closestFont := self shallowCopy |
845 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId; |
848 setDevice: aGraphicsDevice patternId: closestPatternId2 fontId: newFontId; |
846 yourself. |
849 yourself. |
847 aGraphicsDevice registerFont: closestFont. |
850 aGraphicsDevice registerFont: closestFont. |
848 RecentlyUsedFonts addFirst:closestFont. |
851 RecentlyUsedFonts addFirst:closestFont. |
849 ^ closestFont |
852 ^ closestFont |
850 ]. |
853 ]. |
851 ] ensure:[ |
854 ] ensure:[ |
852 myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId]. |
855 myPatternId notNil ifTrue:[self xftPatternDestroy: myPatternId]. |
853 closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1]. |
856 closestPatternId1 notNil ifTrue:[self xftPatternDestroy: closestPatternId1]. |
854 closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2]. |
857 closestPatternId2 notNil ifTrue:[self xftPatternDestroy: closestPatternId2]. |
855 ]. |
858 ]. |
856 |
859 |
857 " |
860 " |
858 (XftFontDescription family:'monospace' size:16) onDevice:Screen current |
861 (XftFontDescription family:'monospace' size:16) onDevice:Screen current |
859 " |
862 " |