Example #1
0
void CmdLabel(int code)
/******************************************************************************
purpose: handles \label \ref \pageref \cite
******************************************************************************/
{
	char *text, *signet, *s;
	char *option = NULL;
	int mode=GetTexMode();
	
	option = getBracketParam();
	text = getBraceParam();
	if (strlen(text)==0) {
		free(text);
		return;
	}
	
	switch (code) {
		case LABEL_LABEL:
			if (g_processing_figure || g_processing_table) break;
			if (mode == MODE_DISPLAYMATH) {
				g_equation_label = strdup_nobadchars(text);
				diagnostics(3,"equation label is <%s>",text);
			} else 
				InsertBookmark(text,"");
			break;
		
		case LABEL_HYPERREF:
		case LABEL_REF:
			signet = strdup_nobadchars(text);
			s = ScanAux("newlabel", text, 1);
			if (g_fields_use_REF) {
				fprintRTF("{\\field{\\*\\fldinst{\\lang1024 REF BM%s \\\\* MERGEFORMAT }}",signet);
				fprintRTF("{\\fldrslt{");
			}
			if (s)
				ConvertString(s);
			else
				fprintRTF("?");
			if (g_fields_use_REF) fprintRTF("}}}");
				
			free(signet);
			if (s) free(s);
			break;
				
		case LABEL_HYPERPAGEREF:
		case LABEL_PAGEREF:
			signet = strdup_nobadchars(text);
			if (g_fields_use_REF) {
				fprintRTF("{\\field{\\*\\fldinst{\\lang1024 PAGEREF BM%s \\\\* MERGEFORMAT }}",signet);
				fprintRTF("{\\fldrslt{");
			}
			fprintRTF("%s",signet);
			if (g_fields_use_REF) fprintRTF("}}}");
			free(signet);
			break;
	}
	
	free(text);
	if (option) free(option);
}
Example #2
0
void Texture::LoadImpl( SDL_Surface *pSurf, int framesCount )
{
  ASSERT( pSurf != 0 );
  Reset();   
  
  ASSERT( framesCount > 0 );
  m_framesCount = framesCount;  
  m_size.set( pSurf->w, pSurf->h );   

  glGenTextures( 1, &m_hTex );
  ASSERT( glGetError() == GL_NO_ERROR );
  ASSERT( m_hTex != INVALID_TEX_HANDLE );

  glBindTexture( GL_TEXTURE_2D, m_hTex ); 
 
  const std::pair<int, int> mode = GetTexMode( pSurf );

  glTexImage2D( GL_TEXTURE_2D, 0, mode.first, pSurf->w, pSurf->h, 0, mode.second, GL_UNSIGNED_BYTE, pSurf->pixels );
  SDL_FreeSurface( pSurf );

  if( glGetError() != GL_NO_ERROR )
    LOG_FATAL( "glTexImage2D error" ); 

  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
}
Example #3
0
void 
TranslateCommand()
/****************************************************************************
purpose: The function is called on a backslash in input file and
	 tries to call the command-function for the following command.
returns: success or not
globals: fTex, fRtf, command-functions have side effects or recursive calls;
         global flags for convert
 ****************************************************************************/
{
	char            cCommand[MAXCOMMANDLEN];
	int             i,mode;
	int             cThis;


	cThis = getTexChar();
	mode = GetTexMode();
	
	diagnostics(5, "Beginning TranslateCommand() \\%c", cThis);

	switch (cThis) {
	case '}':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("\\}");
		return;
	case '{':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("\\{");
		return;
	case '#':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("#");
		return;
	case '$':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("$");
		return;
	case '&':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("&");
		return;
	case '%':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("%%");
		return;
	case '_':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("_");
		return;
		
	case '\\':		/* \\[1mm] or \\*[1mm] possible */
		CmdSlashSlash(0);
		return;
		
	case ' ':
	case '\n':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF(" ");	/* ordinary interword space */
		skipSpaces();
		return;

/* \= \> \< \+ \- \' \` all have different meanings in a tabbing environment */

	case '-':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		} else
			fprintRTF("\\-");
		return;

	case '+':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		}
		return;
		
	case '<':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		}
		return;

	case '>':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			CmdTabjump();
			PushBrace();
		} else 
			CmdSpace(0.50);  /* medium space */
		return;
		
	case '`':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
		} else
			CmdLApostrophChar(0);
		return;
		
	case '\'':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			PushBrace();
			return;
		} else
			CmdRApostrophChar(0);	/* char ' =?= \' */
		return;

	case '=':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		if (g_processing_tabbing){
			(void) PopBrace();
			CmdTabset();
			PushBrace();
		}
		else
			CmdMacronChar(0);
		return;
		
	case '~':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdTildeChar(0);
		return;
	case '^':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdHatChar(0);
		return;
	case '.':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdDotChar(0);
		return;
	case '\"':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdUmlauteChar(0);
		return;
	case '(':
		CmdEquation(EQN_RND_OPEN | ON);
		/*PushBrace();*/
		return;
	case '[':
		CmdEquation(EQN_BRACKET_OPEN | ON);
		/*PushBrace();*/
		return;
	case ')':
		CmdEquation(EQN_RND_CLOSE | OFF);
		/*ret = RecursionLevel - PopBrace();*/
		return;
	case ']':
		CmdEquation(EQN_BRACKET_CLOSE | OFF);
		/*ret = RecursionLevel - PopBrace();*/
		return;
	case '/':
		CmdIgnore(0);		/* italic correction */
		return;
	case '!':
		CmdIgnore(0);		/* \! negative thin space */
		return;
	case ',':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdSpace(0.33);	/* \, produces a small space */
		return;
	case ';':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		CmdSpace(0.75);	/* \; produces a thick space */
		return;
	case '@':
		CmdIgnore(0);	/* \@ produces an "end of sentence" space */
		return;
	case '3':
		if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
		fprintRTF("{\\'df}");	/* german symbol 'รก' */
		return;
	}


	/* LEG180498 Commands consist of letters and can have an optional * at the end */
	for (i = 0; i < MAXCOMMANDLEN; i++) {
		if (!isalpha((int)cThis) && (cThis != '*')) {
			bool            found_nl = FALSE;

			if (cThis == '%'){			/* put the % back and get the next char */
				ungetTexChar('%');
				cThis=getTexChar();
			}

			/* all spaces after commands are ignored, a single \n may occur */
			while (cThis == ' ' || (cThis == '\n' && !found_nl)) {
				if (cThis == '\n')
					found_nl = TRUE;
				cThis = getTexChar();
			}

			ungetTexChar(cThis);	/* put back first non-space char after command */
			break;					/* done skipping spaces */
		} else
			cCommand[i] = cThis;

		cThis = getRawTexChar();	/* Necessary because % ends a command */
	}

	cCommand[i] = '\0';	/* mark end of string with zero */
	diagnostics(5, "TranslateCommand() <%s>", cCommand);

	if (i == 0)
		return;
		
	if (strcmp(cCommand,"begin")==0){
		fprintRTF("{");
		PushBrace();
	}
		
	if (CallCommandFunc(cCommand)){	/* call handling function for command */
		if (strcmp(cCommand,"end")==0) {
			ret = RecursionLevel - PopBrace();
			fprintRTF("}");
		}
		return;
	}
	
	if (TryDirectConvert(cCommand)) return;
	
	if (TryVariableIgnore(cCommand)) return;
		
	diagnostics(WARNING, "Command \\%s not found - ignored", cCommand);
}
Example #4
0
void 
Convert()
/****************************************************************************
purpose: converts inputfile and writes result to outputfile
globals: fTex, fRtf and all global flags for convert (see above)
 ****************************************************************************/
{
	char            cThis = '\n';
	char            cLast = '\0';
	char            cNext;
	int				mode, count,pending_new_paragraph;
	
	diagnostics(3, "Entering Convert ret = %d", ret);
	RecursionLevel++;
	PushLevels();

	while ((cThis = getTexChar()) && cThis != '\0') {
	
		if (cThis == '\n')
			diagnostics(5, "Current character is '\\n' mode = %d ret = %d level = %d", GetTexMode(), ret, RecursionLevel);
		else
			diagnostics(5, "Current character is '%c' mode = %d ret = %d level = %d", cThis, GetTexMode(), ret, RecursionLevel);

		mode = GetTexMode();
		
		pending_new_paragraph--;
		
		switch (cThis) {

		case '\\':
			PushLevels();
			
			TranslateCommand();

			CleanStack();

			if (ret > 0) {
				diagnostics(5, "Exiting Convert via TranslateCommand ret = %d level = %d", ret, RecursionLevel);
				ret--;
				RecursionLevel--;
				return;
			}
			break;
			
			
		case '{':
			if (mode==MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
				
			CleanStack();
			PushBrace();
			fprintRTF("{");
			break;
			
		case '}':
			CleanStack();
			ret = RecursionLevel - PopBrace();
			fprintRTF("}");
			if (ret > 0) {
				diagnostics(5, "Exiting Convert via '}' ret = %d level = %d", ret, RecursionLevel);
				ret--;
				RecursionLevel--;
				return;
			}
			break;

		case ' ':
			if (mode==MODE_VERTICAL || mode==MODE_MATH || mode==MODE_DISPLAYMATH) 
			    	cThis = cLast;
			    						
			else if ( cLast != ' ' && cLast != '\n' ) { 

				if (GetTexMode()==MODE_RESTRICTED_HORIZONTAL)
					fprintRTF("\\~");
				else
					fprintRTF(" ");
			}
			
			break;
			
		case '\n': 
			tabcounter = 0;
			
			if (mode==MODE_MATH || mode==MODE_DISPLAYMATH) {
			
				cNext = getNonBlank();  	
				ungetTexChar(cNext);
			
			} else {
				cNext = getNonSpace(); 
				
				if (cNext == '\n') {			/* new paragraph ... skip all ' ' and '\n' */
					pending_new_paragraph=2;
					CmdEndParagraph(0);
					cNext = getNonBlank();  	
					ungetTexChar(cNext);
					
				} else {						/* add a space if needed */
					ungetTexChar(cNext);
					if (mode != MODE_VERTICAL && cLast != ' ')			
						fprintRTF(" ");  
				}               
			}
			break;


		case '$':
			cNext = getTexChar();
			diagnostics(5,"Processing $, next char <%c>",cNext);

			if (cNext == '$' && GetTexMode() != MODE_MATH)
				CmdEquation(EQN_DOLLAR_DOLLAR | ON);
			else {
				ungetTexChar(cNext);
				CmdEquation(EQN_DOLLAR | ON);
			}

			/* 
			   Formulas need to close all Convert() operations when they end 
			   This works for \begin{equation} but not $$ since the BraceLevel
			   and environments don't get pushed properly.  We do it explicitly here.
			*/
			/*
			if (GetTexMode() == MODE_MATH || GetTexMode() == MODE_DISPLAYMATH)
				PushBrace();
			else {
				ret = RecursionLevel - PopBrace();
				if (ret > 0) {
					ret--;
					RecursionLevel--;
					diagnostics(5, "Exiting Convert via Math ret = %d", ret);
					return;
				}
			}
			*/
			break;

		case '&':
			if (g_processing_arrays) {
				fprintRTF("%c",g_field_separator);
				break;
			}

			if (GetTexMode() == MODE_MATH || GetTexMode() == MODE_DISPLAYMATH) {	/* in eqnarray */
				fprintRTF("\\tab ");
				g_equation_column++;
				break;
			}
			
			if (g_processing_tabular) {	/* in tabular */
				actCol++;
				fprintRTF("\\cell\\pard\\intbl\\q%c ", colFmt[actCol]);
				break;
			}
			fprintRTF("&");
			break;

		case '~':
			fprintRTF("\\~");
			break;			
			
		case '^':		
			CmdSuperscript(0);
			break;

		case '_':		
			CmdSubscript(0);
			break;

		case '-':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) 
				fprintRTF("-");
			else {
				SetTexMode(MODE_HORIZONTAL);
				
				count = getSameChar('-')+1;
				
				if (count == 1) 
					fprintRTF("-");
				else if (count == 2)
					fprintRTF("\\endash ");
				else if (count == 3)
					fprintRTF("\\emdash ");
				else 
					while (count--) fprintRTF("-");
			}
			break;
						
		case '|':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) 
				fprintRTF("|");
			else 
				fprintRTF("\\emdash ");
			break;

		case '\'':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH)
					fprintRTF("'");	
			else {
				SetTexMode(MODE_HORIZONTAL);
				count = getSameChar('\'')+1;
				if (count == 2) 
					fprintRTF("\\rdblquote ");
				else
					while (count--) fprintRTF("\\rquote ");
			}
			break;
			
		case '`':
			SetTexMode(MODE_HORIZONTAL);
			count = getSameChar('`')+1;
			if (count == 2) 
				fprintRTF("\\ldblquote ");
			else
				while (count--) fprintRTF("\\lquote ");
			break;
			
		case '\"':
			SetTexMode(MODE_HORIZONTAL);
			if (GermanMode)
				TranslateGerman();
			else
				fprintRTF("\"");
			break;

		case '<':
			if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
			if (GetTexMode() == MODE_HORIZONTAL){
				cNext = getTexChar();
				if (cNext == '<') {
					if (FrenchMode) {			/* not quite right */
						skipSpaces();
						cNext = getTexChar();
						if (cNext == '~') 
							skipSpaces();
						else
							ungetTexChar(cNext);
						fprintRTF("\\'ab\\~");
					
					} else
						fprintRTF("\\'ab");
				} else {
					ungetTexChar(cNext);
					fprintRTF("<");
				}
			} else
				fprintRTF("<");

			break;

		case '>':
			if (mode == MODE_VERTICAL) SetTexMode(MODE_HORIZONTAL);
			if (GetTexMode() == MODE_HORIZONTAL){
				cNext = getTexChar();
				if (cNext == '>')
					fprintRTF("\\'bb");
				else {
					ungetTexChar(cNext);
					fprintRTF(">");
				}
			} else
				fprintRTF(">");
			break;

		case '!':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH)
				fprintRTF("!");	
			else {
				SetTexMode(MODE_HORIZONTAL);
				if ((cNext = getTexChar()) && cNext == '`') {
					fprintRTF("\\'a1 ");
				} else {
					fprintRTF("! ");
					ungetTexChar(cNext);
				}
			}
			break;	
			
		case '?':
			SetTexMode(MODE_HORIZONTAL);
			if ((cNext = getTexChar()) && cNext == '`') {
				fprintRTF("\\'bf ");
			} else {
				fprintRTF("? ");
				ungetTexChar(cNext);
			}
			break;
			
		case ':':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH)
				fprintRTF(":");	
			else {
				SetTexMode(MODE_HORIZONTAL);
				if (FrenchMode) 
					fprintRTF("\\~:");
  				else
					fprintRTF(":");
			}
			break;	

		case '.':
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH)
				fprintRTF(".");	
			else {
				SetTexMode(MODE_HORIZONTAL);
				fprintRTF(".");
	
				/* try to simulate double spaces after sentences */
				cNext = getTexChar();
				if (0 && cNext == ' ' && (isalpha((int)cLast) && !isupper((int) cLast)))
					fprintRTF(" ");
				ungetTexChar(cNext);
			}
			break;
			
		case '\t':
			diagnostics(WARNING, "This should not happen, ignoring \\t");
			cThis = ' ';
			break;
			
		case '\r':
			diagnostics(WARNING, "This should not happen, ignoring \\r");
			cThis = ' ';
			break;
			
		case '%':
			diagnostics(WARNING, "This should not happen, ignoring %%");
			cThis = ' ';
			break;

		case '(':
			if (g_processing_fields&&g_escape_parent)
				fprintRTF("\\\\(");
			else
				fprintRTF("(");
			break;
			
		case ')':
			if (g_processing_fields&&g_escape_parent)
				fprintRTF("\\\\)");
			else
				fprintRTF(")");
			break;

		case ';':
			if (g_field_separator == ';' && g_processing_fields)
				fprintRTF("\\\\;");
			else
				if (FrenchMode) 
					fprintRTF("\\~;");
  				else
					fprintRTF(";");
		break;

		case ',':
			if (g_field_separator == ',' && g_processing_fields)
				fprintRTF("\\\\,");
			else
				fprintRTF(",");
			break;
			
		default:
			if (mode == MODE_MATH || mode == MODE_DISPLAYMATH) {
				if (('a' <= cThis && cThis <= 'z') || ('A' <= cThis && cThis <= 'Z'))
					fprintRTF("{\\i %c}", cThis);	
				else
					fprintRTF("%c", cThis);	

			} else {
			
				SetTexMode(MODE_HORIZONTAL);
				fprintRTF("%c", cThis);
			}
			break;
		}

		tabcounter++;
		cLast = cThis;
	}
	RecursionLevel--;
	diagnostics(5, "Exiting Convert via exhaustion ret = %d", ret);
}