summaryrefslogtreecommitdiff
path: root/vcl/quartz/CTRunData.cxx
blob: 080052b8c3f1435dd8305e2b155bb91ab1101250 (plain)
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
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <sal/types.h>
#include <cassert>

#include "CTRunData.hxx"

CTRunData::CTRunData( CTRunRef pRun, int start)
    : ownership_flags(0)
    , m_StartPos(start)
    , m_pRun(pRun)
    , m_pAdjPositions(NULL)
{
    assert(pRun);

    CFDictionaryRef pRunAttributes = CTRunGetAttributes( m_pRun );
    m_pFont = (CTFontRef)CFDictionaryGetValue( pRunAttributes, kCTFontAttributeName );

    m_nGlyphs = CTRunGetGlyphCount(m_pRun);
    m_EndPos = m_StartPos + m_nGlyphs;
    const CFRange aAll = CFRangeMake( 0, m_nGlyphs );

    m_pAdvances = CTRunGetAdvancesPtr( pRun );
    if( !m_pAdvances )
    {
        m_pAdvances = new CGSize[m_nGlyphs];
        ownership_flags |= CTRUNDATA_F_OWN_ADVANCES;
        CTRunGetAdvances( pRun, aAll, (CGSize*)m_pAdvances );
    }

    m_pGlyphs = CTRunGetGlyphsPtr( m_pRun );
    if( !m_pGlyphs )
    {
        m_pGlyphs = new CGGlyph[m_nGlyphs];
        ownership_flags |= CTRUNDATA_F_OWN_GLYPHS;
        CTRunGetGlyphs( pRun, aAll, (CGGlyph*)m_pGlyphs);
    }

    m_pStringIndices = CTRunGetStringIndicesPtr( pRun );
    if( !m_pStringIndices )
    {
        m_pStringIndices = new CFIndex[m_nGlyphs];
        ownership_flags |= CTRUNDATA_F_OWN_INDICES;
        CTRunGetStringIndices( pRun, aAll, (CFIndex*)m_pStringIndices );
    }

    m_pPositions = (CGPoint*)CTRunGetPositionsPtr( pRun );
    if( !m_pPositions )
    {
        m_pPositions = new CGPoint[m_nGlyphs];
        ownership_flags |= CTRUNDATA_F_OWN_POSITIONS;
        CTRunGetPositions( pRun, aAll, (CGPoint*)m_pPositions );
    }
}

CTRunData::~CTRunData()
{
    if(ownership_flags & CTRUNDATA_F_OWN_ADVANCES)
    {
        delete [] m_pAdvances;
    }

    if(ownership_flags & CTRUNDATA_F_OWN_GLYPHS)
    {
        delete [] m_pGlyphs;
    }

    if(ownership_flags & CTRUNDATA_F_OWN_INDICES)
    {
        delete [] m_pStringIndices;
    }

    if(ownership_flags & CTRUNDATA_F_OWN_POSITIONS)
    {
        delete [] m_pPositions;
    }
    delete [] m_pAdjPositions;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */