00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #pragma once
00023
00024 #include "STS.h"
00025 #include "Rasterizer.h"
00026 #include "..\SubPic\ISubPic.h"
00027
00028 class CMyFont : public CFont
00029 {
00030 public:
00031 int m_ascent, m_descent;
00032
00033 CMyFont(STSStyle& style);
00034 };
00035
00036 class CPolygon;
00037
00038 class CWord : public Rasterizer
00039 {
00040 bool m_fDrawn;
00041 CPoint m_p;
00042
00043 void Transform(CPoint org);
00044
00045 bool CreateOpaqueBox();
00046
00047 protected:
00048 CStringW m_str;
00049
00050 virtual bool CreatePath() = 0;
00051
00052 public:
00053 bool m_fWhiteSpaceChar, m_fLineBreak;
00054
00055 STSStyle m_style;
00056
00057 CPolygon* m_pOpaqueBox;
00058
00059 int m_ktype, m_kstart, m_kend;
00060
00061 int m_width, m_ascent, m_descent;
00062
00063 CWord(STSStyle& style, CStringW str, int ktype, int kstart, int kend);
00064 virtual ~CWord();
00065
00066 virtual CWord* Copy() = 0;
00067 virtual bool Append(CWord* w);
00068
00069 void Paint(CPoint p, CPoint org);
00070 };
00071
00072 class CText : public CWord
00073 {
00074 protected:
00075 virtual bool CreatePath();
00076
00077 public:
00078 CText(STSStyle& style, CStringW str, int ktype, int kstart, int kend);
00079
00080 virtual CWord* Copy();
00081 virtual bool Append(CWord* w);
00082 };
00083
00084 class CPolygon : public CWord
00085 {
00086 bool GetLONG(CStringW& str, LONG& ret);
00087 bool GetPOINT(CStringW& str, POINT& ret);
00088 bool ParseStr();
00089
00090 protected:
00091 double m_scalex, m_scaley;
00092 int m_baseline;
00093
00094 CArray<BYTE> m_pathTypesOrg;
00095 CArray<CPoint> m_pathPointsOrg;
00096
00097 virtual bool CreatePath();
00098
00099 public:
00100 CPolygon(STSStyle& style, CStringW str, int ktype, int kstart, int kend, double scalex, double scaley, int baseline);
00101 virtual ~CPolygon();
00102
00103 virtual CWord* Copy();
00104 virtual bool Append(CWord* w);
00105 };
00106
00107 class CClipper : public CPolygon
00108 {
00109 private:
00110 CWord* Copy();
00111 virtual bool Append(CWord* w);
00112
00113 public:
00114 CClipper(CStringW str, CSize size, double scalex, double scaley);
00115 virtual ~CClipper();
00116
00117 CSize m_size;
00118 BYTE* m_pAlphaMask;
00119 };
00120
00121 class CLine : public CList<CWord*>
00122 {
00123 public:
00124 int m_width, m_ascent, m_descent, m_border;
00125
00126 virtual ~CLine();
00127
00128 void Compact();
00129
00130 CRect PaintShadow(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00131 CRect PaintOutline(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00132 CRect PaintBody(SubPicDesc& spd, CRect& clipRect, BYTE* pAlphaMask, CPoint p, CPoint org, int time, int alpha);
00133 };
00134
00135 enum eftype
00136 {
00137 EF_MOVE = 0,
00138 EF_ORG,
00139 EF_FADE,
00140 EF_BANNER,
00141 EF_SCROLL,
00142 };
00143
00144 #define EF_NUMBEROFEFFECTS 5
00145
00146 class Effect
00147 {
00148 public:
00149 enum eftype type;
00150 int param[8];
00151 int t[4];
00152 };
00153
00154 class CSubtitle : public CList<CLine*>
00155 {
00156 int GetFullWidth();
00157 int GetFullLineWidth(POSITION pos);
00158 int GetWrapWidth(POSITION pos, int maxwidth);
00159 CLine* GetNextLine(POSITION& pos, int maxwidth);
00160
00161 public:
00162 int m_scrAlignment;
00163 int m_wrapStyle;
00164 bool m_fAnimated;
00165 int m_relativeTo;
00166
00167 Effect* m_effects[EF_NUMBEROFEFFECTS];
00168
00169 CList<CWord*> m_words;
00170
00171 CClipper* m_pClipper;
00172
00173 CRect m_rect, m_clip;
00174 int m_topborder, m_bottomborder;
00175
00176 double m_scalex, m_scaley;
00177
00178 public:
00179 CSubtitle();
00180 virtual ~CSubtitle();
00181 virtual void Empty();
00182
00183 void CreateClippers(CSize size);
00184
00185 void MakeLines(CSize size, CRect marginRect);
00186 };
00187
00188 class CScreenLayoutAllocator
00189 {
00190 typedef struct
00191 {
00192 CRect r;
00193 int segment, entry, layer;
00194 } SubRect;
00195
00196 CList <SubRect, SubRect&> m_subrects;
00197
00198 public:
00199 virtual void Empty();
00200
00201 void AdvanceToSegment(int segment, const CSubArray& sa);
00202 CRect AllocRect(CSubtitle* s, int segment, int entry, int layer, int collisions);
00203 };
00204
00205 [uuid("537DCACA-2812-4a4f-B2C6-1A34C17ADEB0")]
00206 class CRenderedTextSubtitle : public CSimpleTextSubtitle, public ISubPicProviderImpl, public ISubStream
00207 {
00208 CMap <int, int, CSubtitle*, CSubtitle*> m_subtitleCache;
00209
00210 CScreenLayoutAllocator m_sla;
00211
00212 CSize m_size;
00213 CRect m_vidrect;
00214
00215
00216 int m_time, m_delay;
00217 int m_animStart, m_animEnd;
00218 double m_animAccel;
00219 int m_ktype, m_kstart, m_kend;
00220 int m_nPolygon;
00221 int m_polygonBaselineOffset;
00222
00223 void ParseEffect(CSubtitle* sub, CString str);
00224 void ParseString(CSubtitle* sub, CStringW str, STSStyle& style);
00225 void ParsePolygon(CSubtitle* sub, CStringW str, STSStyle& style);
00226 bool ParseSSATag(CSubtitle* sub, CStringW str, STSStyle& style, STSStyle& org, bool fAnimate = false);
00227 bool ParseHtmlTag(CSubtitle* sub, CStringW str, STSStyle& style, STSStyle& org);
00228
00229 double CalcAnimation(double dst, double src, bool fAnimate);
00230
00231 CSubtitle* GetSubtitle(int entry);
00232
00233 protected:
00234 virtual void OnChanged();
00235
00236 public:
00237 CRenderedTextSubtitle(CCritSec* pLock);
00238 virtual ~CRenderedTextSubtitle();
00239
00240 virtual void Copy(CSimpleTextSubtitle& sts);
00241 virtual void Empty();
00242
00243 public:
00244 bool Init(CSize size, CRect vidrect);
00245 void Deinit();
00246
00247 DECLARE_IUNKNOWN
00248 STDMETHODIMP NonDelegatingQueryInterface(REFIID riid, void** ppv);
00249
00250
00251 STDMETHODIMP_(POSITION) GetStartPosition(REFERENCE_TIME rt, double fps);
00252 STDMETHODIMP_(POSITION) GetNext(POSITION pos);
00253 STDMETHODIMP_(REFERENCE_TIME) GetStart(POSITION pos, double fps);
00254 STDMETHODIMP_(REFERENCE_TIME) GetStop(POSITION pos, double fps);
00255 STDMETHODIMP_(bool) IsAnimated(POSITION pos);
00256 STDMETHODIMP Render(SubPicDesc& spd, REFERENCE_TIME rt, double fps, RECT& bbox);
00257
00258
00259 STDMETHODIMP GetClassID(CLSID* pClassID);
00260
00261
00262 STDMETHODIMP_(int) GetStreamCount();
00263 STDMETHODIMP GetStreamInfo(int i, WCHAR** ppName, LCID* pLCID);
00264 STDMETHODIMP_(int) GetStream();
00265 STDMETHODIMP SetStream(int iStream);
00266 STDMETHODIMP Reload();
00267 };