2 * Copyright (C) 2003-2006 Gabest
3 * http://www.gabest.org
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with GNU Make; see the file COPYING. If not, write to
17 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 #include "StringMap.h"
33 StringMapW
<T
> m_key2obj
;
34 CAtlList
<CStringW
> m_objs
;
38 Cache(size_t limit
) {m_limit
= max(1, limit
);}
39 virtual ~Cache() {RemoveAll();}
43 POSITION pos
= m_key2obj
.GetStartPosition();
44 while(pos
) delete m_key2obj
.GetNextValue(pos
);
45 m_key2obj
.RemoveAll();
49 void Add(const CStringW
& key
, T
& obj
, bool fFlush
= true)
51 if(StringMapW
<T
>::CPair
* p
= m_key2obj
.Lookup(key
)) delete p
->m_value
;
52 else m_objs
.AddTail(key
);
61 while(m_objs
.GetCount() > m_limit
)
63 CStringW key
= m_objs
.RemoveHead();
64 ASSERT(m_key2obj
.Lookup(key
));
65 delete m_key2obj
[key
];
66 m_key2obj
.RemoveKey(key
);
70 bool Lookup(const CStringW
& key
, T
& val
)
72 return m_key2obj
.Lookup(key
, val
) && val
;
75 void Invalidate(const CStringW
& key
)
78 if(m_key2obj
.Lookup(key
, val
))
81 m_key2obj
[key
] = NULL
;
86 class FontCache
: public Cache
<FontWrapper
*>
89 FontCache() : Cache(20) {}
90 FontWrapper
* Create(HDC hDC
, const LOGFONT
& lf
);
93 class GlyphPathCache
: public Cache
<GlyphPath
*>
96 GlyphPathCache() : Cache(100) {}
97 GlyphPath
* Create(HDC hDC
, const FontWrapper
* f
, WCHAR c
);
100 class Row
: public CAutoPtrList
<Glyph
>
103 int ascent
, descent
, border
, width
;
104 Row() {ascent
= descent
= border
= width
= 0;}
107 class RenderedSubtitle
112 CAutoPtrList
<Glyph
> m_glyphs
;
114 RenderedSubtitle(const CRect
& spdrc
, const CRect
& clip
) : m_spdrc(spdrc
), m_clip(clip
) {}
115 virtual ~RenderedSubtitle() {}
117 CRect
Draw(SubPicDesc
& spd
) const;
120 class RenderedSubtitleCache
: public Cache
<RenderedSubtitle
*>
123 RenderedSubtitleCache() : Cache(10) {}
132 SubRect(const CRect
& r
, float l
) : rect(r
), layer(l
) {}
135 class SubRectAllocator
: public StringMapW
<SubRect
>
140 void UpdateTarget(const CSize
& vs
, const CRect
& vr
);
141 void GetRect(CRect
& rect
, const Subtitle
* s
, const Align
& align
, int tlb
, int brb
);
149 GlyphPathCache m_gpc
;
150 RenderedSubtitleCache m_rsc
;
151 SubRectAllocator m_sra
;
157 void NextSegment(const CAutoPtrList
<Subtitle
>& subs
);
158 RenderedSubtitle
* Lookup(const Subtitle
* s
, const CSize
& vs
, const CRect
& vr
);