Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 68a66a4ab3
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 95 lines (76 sloc) 2.481 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
/*
* QuartzTextStyle.h
* wtf
*
* Created by Evan Jones on Wed Oct 02 2002.
* Copyright (c) 2002 __MyCompanyName__. All rights reserved.
*
*/

#include <Carbon/Carbon.h>

#ifndef _QUARTZ_TEXT_STYLE_H
#define _QUARTZ_TEXT_STYLE_H

#include "QuartzTextStyleAttribute.h"

class QuartzTextStyle
{
public:
    QuartzTextStyle()
    {
        ATSUCreateStyle( &style );
    }

    ~QuartzTextStyle()
    {
        if ( style != NULL )
            ATSUDisposeStyle( style );
        style = NULL;
    }

    void setAttribute( ATSUAttributeTag tag, ByteCount size, ATSUAttributeValuePtr value )
    {
        ATSUSetAttributes( style, 1, &tag, &size, &value );
    }

    void setAttribute( QuartzTextStyleAttribute& attribute )
    {
        setAttribute( attribute.getTag(), attribute.getSize(), attribute.getValuePtr() );
    }

    void getAttribute( ATSUAttributeTag tag, ByteCount size, ATSUAttributeValuePtr value, ByteCount* actualSize )
    {
        ATSUGetAttribute( style, tag, size, value, actualSize );
    }

    template <class T>
    T getAttribute( ATSUAttributeTag tag )
    {
        T value;
        ByteCount actualSize;
        ATSUGetAttribute( style, tag, sizeof( T ), &value, &actualSize );
        return value;
    }

    // TODO: Is calling this actually faster than calling setAttribute multiple times?
    void setAttributes( QuartzTextStyleAttribute* attributes[], int number )
    {
        // Create the parallel arrays and initialize them properly
        ATSUAttributeTag* tags = new ATSUAttributeTag[ number ];
        ByteCount* sizes = new ByteCount[ number ];
        ATSUAttributeValuePtr* values = new ATSUAttributeValuePtr[ number ];

        for ( int i = 0; i < number; ++ i )
        {
            tags[i] = attributes[i]->getTag();
            sizes[i] = attributes[i]->getSize();
            values[i] = attributes[i]->getValuePtr();
        }
        
        ATSUSetAttributes( style, number, tags, sizes, values );

        // Free the arrays that were allocated
        delete[] tags;
        delete[] sizes;
        delete[] values;
    }

    void setFontFeature( ATSUFontFeatureType featureType, ATSUFontFeatureSelector selector )
    {
        ATSUSetFontFeatures( style, 1, &featureType, &selector );
    }

    const ATSUStyle& getATSUStyle() const
    {
        return style;
    }

private:
    ATSUStyle style;
};

#endif

Something went wrong with that request. Please try again.