Exemple #1
0
def getFont(familyName, size=200, location=None):
    attributes = {CoreText.kCTFontFamilyNameAttribute: familyName}
    descriptor = CoreText.CTFontDescriptorCreateWithAttributes(attributes);
    if location:
        for tag, value in location.items():
            descriptor = CoreText.CTFontDescriptorCreateCopyWithVariable(descriptor, tagToInt(tag), value)
    return CoreText.CTFontCreateWithFontDescriptor(descriptor, size, [1, 0, 0, 1, 0, 0])
    def testFunctions(self):

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateWithAttributes)
        v = CoreText.CTFontDescriptorCreateWithAttributes({
            CoreText.kCTFontNameAttribute:
            "Optima Bold",
            CoreText.kCTFontSizeAttribute:
            "23.4",
        })
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateWithNameAndSize)
        v = CoreText.CTFontDescriptorCreateWithNameAndSize("Optima Bold", 15.0)
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)
        descriptor = v

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateCopyWithAttributes)
        v = CoreText.CTFontDescriptorCreateCopyWithAttributes(
            v, {"foo": "bar"})
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateCopyWithVariation)
        v = CoreText.CTFontDescriptorCreateCopyWithVariation(v, 0, 5.0)
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateCopyWithFeature)
        v = CoreText.CTFontDescriptorCreateCopyWithFeature(v, 0, 6)
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateMatchingFontDescriptors)
        v = CoreText.CTFontDescriptorCreateMatchingFontDescriptors(
            descriptor, None)
        self.assertIsInstance(v, CoreText.CFArrayRef)

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCreateMatchingFontDescriptor)
        v = CoreText.CTFontDescriptorCreateMatchingFontDescriptor(
            descriptor, None)
        self.assertIsInstance(v, CoreText.CTFontDescriptorRef)

        self.assertResultIsCFRetained(CoreText.CTFontDescriptorCopyAttributes)
        v = CoreText.CTFontDescriptorCopyAttributes(descriptor)
        self.assertIsInstance(v, CoreText.CFDictionaryRef)

        self.assertResultIsCFRetained(CoreText.CTFontDescriptorCopyAttribute)
        v = CoreText.CTFontDescriptorCopyAttribute(
            descriptor, CoreText.kCTFontNameAttribute)
        self.assertEqual(v, "Optima Bold")

        self.assertResultIsCFRetained(
            CoreText.CTFontDescriptorCopyLocalizedAttribute)
        self.assertArgIsOut(CoreText.CTFontDescriptorCopyLocalizedAttribute, 2)
        v, locattr = CoreText.CTFontDescriptorCopyLocalizedAttribute(
            descriptor, CoreText.kCTFontDisplayNameAttribute, None)
        self.assertIsInstance(v, str)
        self.assertIsInstance(locattr, (str, type(None)))

        v = CoreText.CTFontDescriptorGetTypeID()
        self.assertIsInstance(v, int)