示例#1
0
Baseline *  Array::GetBaseline(int sta1, int sta2)
{
    // First enforce sta1 < sta2
    Sort(sta1, sta2);

    string sta1name = GetStation(sta1)->GetName();
    string sta2name = GetStation(sta2)->GetName();
    
    return GetBaseline(sta1name + "-" + sta2name);
}
示例#2
0
void
PutLatexFile(char *s, double scale, char *pre)
/******************************************************************************
 purpose   : Convert LaTeX to Bitmap and insert in RTF file
 ******************************************************************************/
{
	char *png, *cmd, *l2p;
	int err, baseline,second_pass;
	size_t cmd_len;
	unsigned long width, height, rw, rh;
	unsigned long maxsize=(unsigned long) (32767.0/20.0);
	int resolution = g_dots_per_inch; /*points per inch */
	
	diagnostics(4, "Entering PutLatexFile");

	png = strdup_together(s,".png");
	l2p = get_latex2png_name();

	cmd_len = strlen(l2p)+strlen(s)+25;
	if (g_home_dir)
		cmd_len += strlen(g_home_dir);

	cmd = (char *) malloc(cmd_len);

	do {
		second_pass = FALSE; 	/* only needed if png is too large for Word */
		if (g_home_dir==NULL)
			snprintf(cmd, cmd_len, "%s -d %d %s", l2p, resolution, s);	
		else
			snprintf(cmd, cmd_len, "%s -d %d -H \"%s\" %s", l2p, resolution, g_home_dir, s);	

		diagnostics(2, "system graphics command = [%s]", cmd);
		err=system(cmd);
		if (err) break;

		GetPngSize(png, &width, &height);
		baseline=GetBaseline(s, pre);
		diagnostics(4, "png size height=%d baseline=%d width=%d", height, baseline, width);
		
		if( (width>maxsize && height!=0) || (height>maxsize && width!=0) ){  
			second_pass = TRUE;
			rw=(unsigned long) ((resolution*maxsize)/width);
		 	rh=(unsigned long) ((resolution*maxsize)/height); 
			resolution=rw<rh?(int)rw:(int)rh;
		}
	} while (resolution>10 && ( (width>maxsize) || (height>maxsize)) );
	
	if (err==0)
		PutPngFile(png, scale*72.0/resolution, (double) baseline, TRUE);
	
	free(l2p);
	free(png);
	free(cmd);
}
示例#3
0
void scCachedStyle::ComputeExtentsnCursor( void )
{
	if ( GetDeviceValues() ) {
		scXRect 		rect;
		MicroPoint		a,b,c,d;

		FIgetDEVFontExtents( fSpec, a, b, c, d, rect );

		if ( fFlowDir.IsHorizontal() ) {
			scAssert( rect.Valid( eFirstQuad ) );
			rect.FirstToFourth( GetPtSize() );
			scAssert( rect.Valid( eFourthQuad ) );
			
			fInkExtents.y1	= rect.y1;
			fInkExtents.y2	= rect.y2;
			fInkExtents.x1	= rect.x1;
			fInkExtents.x2	= rect.x2;
		}
		else {
			fInkExtents.y1	= 0;
			fInkExtents.y2	= rect.y1 - rect.y2;
			fInkExtents.x1	= -(rect.x2/2) - rect.x1;
			fInkExtents.x2	= rect.x2/2;
		}
	}
	else {
		scRLURect		rect;
		RLU 			a,b,c,d;

		FIgetRLUFontExtents( fSpec, a, b, c, d, rect );

		if ( fFlowDir.IsHorizontal() ) {
			scAssert( rect.Valid( eFirstQuad ) );
			rect.FirstToFourth( scBaseRLUsystem );
		}
		scAssert( rect.Valid( eFourthQuad ) );

		fInkExtents.y1	= scRoundMP( fPtConv * rect.rluTop );
		fInkExtents.y2	= scRoundMP( fPtConv * rect.rluBottom );
		fInkExtents.x1	= scRoundMP( fSetConv * rect.rluLeft );
		fInkExtents.x2	= scRoundMP( fSetConv * rect.rluRight );		

	}

	REAL obliqOff = 0;
	if (  GetHorzOblique()	)
		obliqOff = (REAL)tan( AngleToRadians( GetHorzOblique() ) );

	if ( GetHorzOblique() < 0 )
		 fInkExtents.x1 += scRoundMP( GetPtSize() * obliqOff );

	if ( GetHorzOblique() < 0 ) 
		fInkExtents.x2 += scRoundMP( GetPtSize() * obliqOff );

	scAssert( fInkExtents.Valid( eFourthQuad ) );
	
	if ( fFlowDir.IsHorizontal() )
		fInkExtents.Translate( 0, -GetBaseline() );
	else 
		fInkExtents.Translate( GetBaseline(), 0 );	
	
	if ( fFlowDir.IsHorizontal() ) {
		scLEADRefData	ld;

		ld.Set( GetPtSize(), fFlowDir );
		fLogicalExtents.Set( 0, -ld.GetAboveLead(),
							 GetSetSize(), ld.GetBelowLead() ); 												
	}
	else
		fLogicalExtents.Set( -GetSetSize()/2, 0, GetSetSize()/2, GetPtSize() );

	
	if ( fFlowDir.IsHorizontal() ) {
		fCursorY1		= -scRoundMP( fPtConv * RLU_BASEfmTop );
		fCursorY2		= scRoundMP( fPtConv * RLU_BASEfmBottom );
	}
	else {
		fCursorX1		= -GetSetSize() / 2;
		fCursorX2		= GetSetSize() / 2;
	}
}
示例#4
0
void CHTMLSectionCreator::AdjustShapeBaselinesAndHorizontalAlignment()
//
//	Adjust the shapes baselines to allow for different heights and styles of text
{
	int nHorizontalDelta = 0;

	//
	//	Horizontally align the shapes.
	//
	//	Get the horizontal extent of allof the shapes.
	//	if right aligned then move allthe shapes on the line by the difference
	//		between the width between the margins and the line extent.
	//	if centre aligned then move the shapes half the difference between the
	//		margins and the line extent.
	if( !m_bMeasuring && m_algCurrentPargraph != CStyle::algLeft && m_nFirstShapeOnLine != GetCurrentShapeID() )
	{
		const int nCurrentShape = GetCurrentShapeID() - 1;
		const CSectionABC *psectFirst = GetHTMLSection()->GetSectionAt( m_nFirstShapeOnLine );
		const CSectionABC *psectSecond = GetHTMLSection()->GetSectionAt( nCurrentShape );
		const int nExtent =  psectSecond->right -  psectFirst->left;
		const int nSpaceWidth = m_nLineWidth - nExtent;
		if( m_algCurrentPargraph == CStyle::algCentre )
		{
			// richg - 19990225 - Never shift left!
			nHorizontalDelta = max( 0, nSpaceWidth / 2 );
		}
		else if( m_algCurrentPargraph == CStyle::algRight )
		{
			// richg - 19990225 - Never shift left!
			nHorizontalDelta = max( 0, nSpaceWidth );
		}
	}

	//
	//	Minus one is a signal that the shapes are all the same size.
	m_nNextYPos = GetCurrentYPos();

	const int nCurrentShapeID = GetCurrentShapeID();
	if( m_nFirstShapeOnLine != nCurrentShapeID )
	{
		for( int n = m_nFirstShapeOnLine; n < nCurrentShapeID; n++ )
		{
			CSectionABC *pSect = GetHTMLSection()->GetSectionAt( n );
			const int nBaseline = GetBaseline( n );
			if( nBaseline >= 0 )
			{
				const int nBaselineDelta = m_nLowestBaseline - nBaseline;
				if( nBaselineDelta || nHorizontalDelta )
				{
					pSect->MoveXY( nHorizontalDelta, nBaselineDelta );
				}

				//
				//	We only use shapes that have a baseline
				if( pSect->bottom > m_nNextYPos )
				{
					m_nNextYPos = pSect->bottom;
				}
			}

			if( pSect->right > m_nWidth )
				m_nWidth = pSect->right;
		}
	}
}
示例#5
0
bool udtBaseParser::ParsePacketEntities(udtMessage& msg, idClientSnapshotBase* oldframe, idClientSnapshotBase* newframe)
{
	_inChangedEntities.Clear();
	_inRemovedEntities.Clear();

	newframe->parseEntitiesNum = _inParseEntitiesNum;
	newframe->numEntities = 0;

	// delta from the entities present in oldframe
	s32	oldnum;
	s32	newnum;
	s32 oldindex = 0;
	idEntityStateBase* oldstate = NULL;
	if(!oldframe) 
	{
		oldnum = 99999;
	} 
	else 
	{
		if(oldindex >= oldframe->numEntities) 
		{
			oldnum = 99999;
		} 
		else 
		{
			oldstate = GetEntity((oldframe->parseEntitiesNum + oldindex) & (ID_MAX_PARSE_ENTITIES-1));
			oldnum = oldstate->number;
		}
	}

	for(;;)
	{
		newnum = msg.ReadBits(GENTITYNUM_BITS);

		if(newnum == (MAX_GENTITIES - 1))
		{
			break;
		}

		if(!msg.ValidState()) 
		{
			return false;
		}

		while(oldnum < newnum) 
		{
			//
			// One or more entities from the old packet is unchanged.
			//

			if(!DeltaEntity(msg, newframe, oldnum, oldstate, true)) return false;
			oldindex++;

			if(oldindex >= oldframe->numEntities) 
			{
				oldnum = 99999;
			} 
			else 
			{
				oldstate = GetEntity((oldframe->parseEntitiesNum + oldindex) & (ID_MAX_PARSE_ENTITIES-1));
				oldnum = oldstate->number;
			}
		}

		if(oldnum == newnum)
		{
			//
			// Delta from previous state.
			//

			if(!DeltaEntity(msg, newframe, newnum, oldstate, false)) return false;
			oldindex++;

			if(oldindex >= oldframe->numEntities) 
			{
				oldnum = 99999;
			} 
			else
			{
				oldstate = GetEntity((oldframe->parseEntitiesNum + oldindex) & (ID_MAX_PARSE_ENTITIES-1));
				oldnum = oldstate->number;
			}
			continue;
		}

		if(oldnum > newnum) 
		{
			//
			// Delta from the baseline.
			//

			if(!DeltaEntity(msg, newframe, newnum, GetBaseline(newnum), false)) return false;
			continue;
		}
	}

	// Any remaining entities in the old frame are copied over.
	while(oldnum != 99999) 
	{
		//
		// One or more entities from the old packet is unchanged.
		//

		if(!DeltaEntity(msg, newframe, oldnum, oldstate, true)) return false;
		oldindex++;

		if(oldindex >= oldframe->numEntities) 
		{
			oldnum = 99999;
		} 
		else 
		{
			oldstate = GetEntity((oldframe->parseEntitiesNum + oldindex) & (ID_MAX_PARSE_ENTITIES-1));
			oldnum = oldstate->number;
		}
	}

	return true;
}
示例#6
0
void udtBaseParser::WriteGameState()
{
	_outMsg.Init(_outMsgData, sizeof(_outMsgData));
	_outMsg.Bitstream();

	_outMsg.WriteLong(_inReliableSequenceAcknowledge);

	_outMsg.WriteByte(svc_gamestate);
	_outMsg.WriteLong(_outServerCommandSequence);
	++_outServerCommandSequence;

	_protocolConverter->StartGameState();
	
	// Config strings.
	for(u32 i = 0; i < (u32)UDT_COUNT_OF(_inConfigStrings); ++i)
	{
		const udtString& cs = _inConfigStrings[i];
		if(_outProtocol == _inProtocol && !udtString::IsNullOrEmpty(cs))
		{
			_outMsg.WriteByte(svc_configstring);
			_outMsg.WriteShort((s32)i);
			_outMsg.WriteBigString(cs.GetPtr(), cs.GetLength());
			continue;
		}

		udtVMScopedStackAllocator allocatorScope(_tempAllocator);
		
		udtConfigStringConversion outCs;
		_protocolConverter->ConvertConfigString(outCs, _tempAllocator, (s32)i, cs.GetPtr(), cs.GetLength());
		if(outCs.Index >= 0 && outCs.String.GetLength() > 0)
		{
			_outMsg.WriteByte(svc_configstring);
			_outMsg.WriteShort(outCs.Index);
			_outMsg.WriteBigString(outCs.String.GetPtr(), outCs.String.GetLength());
		}
	}

	idLargestEntityState nullState;
	Com_Memset(&nullState, 0, sizeof(nullState));
	
	// Baseline entities.
	for(s32 i = 0; i < ID_MAX_PARSE_ENTITIES; ++i)
	{
		// We delta from the null state because we write a full entity.
		const idEntityStateBase* const newState = GetBaseline(i);

		// Write the baseline entity if it's not filled with 0 integers.
		if(memcmp(&nullState, newState, _inProtocolSizeOfEntityState))
		{
			_outMsg.WriteByte(svc_baseline);

			// @NOTE: MSG_WriteBits is called in there with newState.number as an argument.
			idLargestEntityState newStateOutProto;
			_protocolConverter->ConvertEntityState(newStateOutProto, *newState);
			_outMsg.WriteDeltaEntity(&nullState, &newStateOutProto, true);
		}
	}
	
	_outMsg.WriteByte(svc_EOF);

	_outMsg.WriteLong(_inClientNum);
	_outMsg.WriteLong(_inChecksumFeed);

	_outMsg.WriteByte(svc_EOF);
}
示例#7
0
bool udtBaseParser::ParseGamestate()
{
	// @TODO: Reset some data, but not for the 1st gamestate message.
	ResetForGamestateMessage();

	// A game state always marks a server command sequence.
	_inServerCommandSequence = _inMsg.ReadLong();

	//
	// Parse all the config strings and baselines.
	//

	for(;;)
	{
		const s32 command = _inMsg.ReadByte();

		if(_inProtocol <= udtProtocol::Dm48 && command == svc_bad)
		{
			break;
		}

		if(command == svc_EOF)
		{
			break;
		}

		if(command == svc_configstring)
		{
			const s32 index = _inMsg.ReadShort();
			if(index < 0 || index >= MAX_CONFIGSTRINGS) 
			{
				_context->LogError("udtBaseParser::ParseGamestate: Config string index out of range: %d (in file: %s)", index, GetFileNamePtr());
				return false;
			}

			s32 configStringLength = 0;
			const char* const configStringTemp = _inMsg.ReadBigString(configStringLength);
			
			// Copy the string to a safe location.
			_inConfigStrings[index] = udtString::NewClone(_configStringAllocator, configStringTemp, configStringLength);
		} 
		else if(command == svc_baseline)
		{
			const s32 newIndex = _inMsg.ReadBits(GENTITYNUM_BITS);
			if(newIndex < 0 || newIndex >= MAX_GENTITIES) 
			{
				_context->LogError("udtBaseParser::ParseGamestate: Baseline number out of range: %d (in file: %s)", newIndex, GetFileNamePtr());
				return false;
			}
			
			idLargestEntityState nullState;
			idEntityStateBase* const newState = GetBaseline(newIndex);

			// We delta from the null state because we read a full entity.
			Com_Memset(&nullState, 0, sizeof(nullState));
			bool addedOrChanged = false;
			if(!_inMsg.ReadDeltaEntity(addedOrChanged, &nullState, newState, newIndex))
			{
				return false;
			}
		} 
		else 
		{
			_context->LogError("udtBaseParser::ParseGamestate: Unrecognized command byte: %d (in file: %s)", command, GetFileNamePtr());
			return false;
		}
	}

	if(_inProtocol >= udtProtocol::Dm66)
	{
		_inClientNum = _inMsg.ReadLong();
		_inChecksumFeed = _inMsg.ReadLong();
	}
	else
	{
		_inClientNum = -1;
		_inChecksumFeed = 0;
	}

	if(EnablePlugIns && !PlugIns.IsEmpty())
	{
		udtGamestateCallbackArg info;
		info.ServerCommandSequence = _inServerCommandSequence;
		info.ClientNum = _inClientNum;
		info.ChecksumFeed = _inChecksumFeed;

		for(u32 i = 0, count = PlugIns.GetSize(); i < count; ++i)
		{
			PlugIns[i]->ProcessGamestateMessage(info, *this);
		}
	}

	++_inGameStateIndex;
	_inGameStateFileOffsets.Add(_inFileOffset);

	return true;
}
示例#8
0
//
// Write a delta update of an entityState_t list to the output message.
//
void udtBaseParser::EmitPacketEntities(idClientSnapshotBase* from, idClientSnapshotBase* to)
{
	idEntityStateBase* oldent = 0;
	idEntityStateBase* newent = 0;
	s32 oldindex = 0;
	s32 newindex = 0;
	s32 oldnum;
	s32 newnum;

	s32 from_num_entities;
	if(!from) 
	{
		from_num_entities = 0;
	} 
	else 
	{
		from_num_entities = from->numEntities;
	}

	while(newindex < to->numEntities || oldindex < from_num_entities) 
	{
		if(newindex >= to->numEntities) 
		{
			newnum = 9999;
		} 
		else 
		{
			s32 entNum = (to->parseEntitiesNum + newindex) & (ID_MAX_PARSE_ENTITIES - 1);
			newent = GetEntity(entNum);
			newnum = newent->number;
		}

		if(oldindex >= from_num_entities) 
		{
			oldnum = 9999;
		}
		else 
		{
			s32 entNum = (from->parseEntitiesNum + oldindex) & (ID_MAX_PARSE_ENTITIES - 1);
			oldent = GetEntity(entNum);
			oldnum = oldent->number;
		}

		if(newnum == oldnum)
		{
			// Delta update from old position
			// because the force parameter is qfalse, this will not result
			// in any bytes being emitted if the entity has not changed at all.
			idLargestEntityState oldEntOutProto;
			idLargestEntityState newEntOutProto;
			_protocolConverter->ConvertEntityState(oldEntOutProto, *oldent);
			_protocolConverter->ConvertEntityState(newEntOutProto, *newent);
			_outMsg.WriteDeltaEntity(&oldEntOutProto, &newEntOutProto, false);
			oldindex++;
			newindex++;
			continue;
		}

		if(newnum < oldnum) 
		{
			// This is a new entity, send it from the baseline.
			idLargestEntityState baselineOutProto;
			idLargestEntityState newEntOutProto;
			idEntityStateBase* baseline = GetBaseline(newnum);
			_protocolConverter->ConvertEntityState(baselineOutProto, *baseline);
			_protocolConverter->ConvertEntityState(newEntOutProto, *newent);
			_outMsg.WriteDeltaEntity(&baselineOutProto, &newEntOutProto, true);
			newindex++;
			continue;
		}

		if(newnum > oldnum) 
		{
			// The old entity isn't present in the new message.
			idLargestEntityState oldEntOutProto;
			_protocolConverter->ConvertEntityState(oldEntOutProto, *oldent);
			_outMsg.WriteDeltaEntity(&oldEntOutProto, NULL, true);
			oldindex++;
			continue;
		}
	}

	_outMsg.WriteBits(MAX_GENTITIES - 1, GENTITYNUM_BITS);
}