⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subtitle.c

📁 tcpmp外挂字幕插件subs_src 源码
💻 C
字号:
/*****************************************************************************
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * File    : subtitle.c
 * Created : 05/01/08
 * Purpose : Load and draw subtitles on a Pocket PC device.
 *
 * The Core Pocket Media Player SUBS Subtitle Plugin
 * Copyright (c) 2008 Alexander Sorokin
/****************************************************************************/

#include "subtitle.h"

int xfonts_len=1;
const wchar_t supported[100]=L"ass.ssa.smi.sami.srt";

HPEN clear_pen;
HBRUSH clear_brush;

// Create a new font for drawing
void xfonts_add(int id,xfont *fnt)
{
	LOGFONT logfont;
	if (id<0) {id=xfonts_len; xfonts_len++;}
	memcpy(&xfonts[id],fnt,sizeof(xfont));
	if (!xfonts[id].height) xfonts[id].height=xsubs.def_height*xsubs.device_width/240;
	if (id>SUBS_MAX_FONTS) return;
	xfonts_free(id);
	logfont.lfHeight = xfonts[id].height;
	logfont.lfWidth  = 0;
	logfont.lfEscapement = 0;
	logfont.lfOrientation = 0;
	logfont.lfWeight = xfonts[id].bold*FW_BOLD;
	logfont.lfItalic = xfonts[id].italic;
	logfont.lfUnderline = xfonts[id].underline;
	logfont.lfStrikeOut = xfonts[id].strikeout;
	logfont.lfCharSet = DEFAULT_CHARSET;
	logfont.lfOutPrecision = OUT_DEFAULT_PRECIS;
	logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
	logfont.lfQuality = DEFAULT_QUALITY;
	logfont.lfPitchAndFamily = DEFAULT_PITCH;
	if (xfonts[id].font) wcscpy(logfont.lfFaceName,xfonts[id].font); else logfont.lfFaceName[0]='\0';
	xfonts[id].h = CreateFontIndirect(&logfont);
	logfont.lfEscapement = 900;
	logfont.lfOrientation = 900;
	xfonts[id].v = CreateFontIndirect(&logfont);
}

// Free font
void xfonts_free(int id)
{
	if (xfonts[id].h) DeleteObject(xfonts[id].h);
	if (xfonts[id].v) DeleteObject(xfonts[id].v);
}

// Initialize Drawing Objects
void xsubs_init(wchar_t * fn)
{
	int i;
	xsubs.file=0;
	xsubs.last=0;
	for (i=0;i<SUBS_MAX_FONTS;i++) xfonts[i].h=xfonts[i].v=0;
	xsubs_init_font();
	clear_pen=CreatePen(PS_NULL,0,xsubs.clear_color);
	clear_brush=CreateSolidBrush(xsubs.clear_color);
	xsubs.dirtystate=0;
	xsubs_load(fn);
}

void xsubs_init_font(void)
{
	xfont std;
	memset(&std,0,sizeof(xfont));
	std.fgcolor=0x00FFFFFF;
	std.bold=xsubs.def_bold;
	std.outlined=xsubs.def_outlined;
	std.font=xsubs.def_font;
	xfonts_add(0,&std);
}

// Load subtitles from a file
void xsubs_load(wchar_t * fn)
{
	char* temp;
	DWORD len;
	DWORD r,w; // Number of read bytes
	HANDLE f;
	wchar_t *pos,*sup;
	sup=(wchar_t *)&supported;
	f=INVALID_HANDLE_VALUE;
	while (sup && f==INVALID_HANDLE_VALUE)
	{
		pos=wcsrchr(fn,'.');
		if (pos) pos[1]='\0';
		wcsncat(fn,sup,wcschr(sup,'.')-sup);
		sup=wcschr(sup,'.');
		if (sup) sup++;
		f=CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0);
	}
	if (f == INVALID_HANDLE_VALUE) return;
	len = GetFileSize(f, 0);
	if (len > SUBS_MAX_FILE_LENGTH) return;
	temp = (char *)malloc((len + 16) * sizeof(char));
	ReadFile(f, temp, len, &r, 0);
	if (r!=len) {free(temp); return;}
	// Check if file is UNICODE
	if (temp[0]=='

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -