<commit_before>/* libwpd2
 * Copyright (C) 2002 <NAME> (<EMAIL>)
 * Copyright (C) 2002 <NAME> (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * For further information visit http://libwpd.sourceforge.net
 */

/* "This product is not manufactured, approved, or supported by 
 * Corel Corporation or Corel Corporation Limited."
 */
#include <string.h>

#include "WP6FontDescriptorPacket.h"
#include "libwpd_internal.h"

static char *fontWeightStrings[] = { "Regular", "Bold" };
static int numFontWeightStrings = 2;

WP6FontDescriptorPacket::WP6FontDescriptorPacket(GsfInput *input, int id, guint32 dataOffset, guint32 dataSize) 
	: WP6PrefixDataPacket(input, id)
{
	_read(input, dataOffset, dataSize);
}

WP6FontDescriptorPacket::~WP6FontDescriptorPacket()
{
	delete [] m_fontName;
}

void WP6FontDescriptorPacket::_readContents(GsfInput *input)
{
   // short sized characteristics
   m_characterWidth = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_ascenderHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_xHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_descenderHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_italicsAdjust = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   // byte sized characteristics
   m_primaryFamilyMemberId = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_primaryFamilyId = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_scriptingSystem = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_primaryCharacterSet = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_width = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_weight = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_attributes = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_generalCharacteristics = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_classification = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fill = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fontType = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fontSourceFileType = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);

   m_fontNameLength = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL); 

   // TODO: re-do sanity checking
   //if(m_fontNameLength < WP_FONT_NAME_MAX_LENGTH)
   //{	
   if (m_fontNameLength == 0) 
	   {
		   m_fontName = new gchar[1];
		   m_fontName[0]='\0';
	   }
   
   else 
	   {
		   gchar const *tempFontName = (gchar const *)gsf_input_read(input, sizeof(gchar)*m_fontNameLength, NULL);
		   m_fontName = new gchar[m_fontNameLength];

		   guint16 tempLength1=0;
		   int numTokens=0;
		   int lastTokenPosition=0;
		   for (guint16 i=0; i<m_fontNameLength; i++) 
			   {
				   if (tempFontName[i] == 0x20) {
					   m_fontName[tempLength1]=' ';
					   tempLength1++;
					   numTokens++;
					   lastTokenPosition=tempLength1;
				   }
				   else if (tempFontName[i] != 0x00) {
					   m_fontName[tempLength1]=tempFontName[i];
					   tempLength1++;
				   }
			   }
		   m_fontName[tempLength1]='\0';
		   // TODO/HACK: probably should create a proper static function for doing this
		   // consume the last token (by replacing the first char with a null-terminator) if its a weight signifier
		   // (NB: not all wp fonts are terminated by weight, just enough of them to make this annoying
		   for (int j=0; j<numFontWeightStrings; j++) 
			   {
				   if (!strcmp(fontWeightStrings[j], &m_fontName[lastTokenPosition])) 
					   {
						   if (lastTokenPosition > 0)
							   m_fontName[lastTokenPosition-1]='\0';
						   break;
					   }
			   }
	   }

   //
   
   //}
   //    else
   //      return gIE_IMPORTERROR;
   WPD_DEBUG_MSG(("WordPerfect: Read Font (primary family id: %i, family member id: %i, font type: %i, font source file type: %i font name length: %i, font name: %s)\n", (int) m_primaryFamilyId, (int) m_primaryFamilyMemberId, (int) m_fontType, (int) m_fontSourceFileType, (int) m_fontNameLength, m_fontName));

}

<commit_msg>try to work around strange dutch font names :)<commit_after>/* libwpd2
 * Copyright (C) 2002 <NAME> (<EMAIL>)
 * Copyright (C) 2002 <NAME> (<EMAIL>)
 *  
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 * For further information visit http://libwpd.sourceforge.net
 */

/* "This product is not manufactured, approved, or supported by 
 * Corel Corporation or Corel Corporation Limited."
 */
#include <string.h>

#include "WP6FontDescriptorPacket.h"
#include "libwpd_internal.h"

static char *fontWeightStrings[] = { "Regular", "Bold", "Standaard", "Standard" };
static int numFontWeightStrings = 4;

WP6FontDescriptorPacket::WP6FontDescriptorPacket(GsfInput *input, int id, guint32 dataOffset, guint32 dataSize) 
	: WP6PrefixDataPacket(input, id)
{
	_read(input, dataOffset, dataSize);
}

WP6FontDescriptorPacket::~WP6FontDescriptorPacket()
{
	delete [] m_fontName;
}

void WP6FontDescriptorPacket::_readContents(GsfInput *input)
{
   // short sized characteristics
   m_characterWidth = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_ascenderHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_xHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_descenderHeight = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   m_italicsAdjust = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL);
   // byte sized characteristics
   m_primaryFamilyMemberId = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_primaryFamilyId = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_scriptingSystem = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_primaryCharacterSet = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_width = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_weight = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_attributes = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_generalCharacteristics = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_classification = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fill = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fontType = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);
   m_fontSourceFileType = *(const guint8 *)gsf_input_read(input, sizeof(guint8), NULL);

   m_fontNameLength = *(const guint16 *)gsf_input_read(input, sizeof(guint16), NULL); 

   // TODO: re-do sanity checking
   //if(m_fontNameLength < WP_FONT_NAME_MAX_LENGTH)
   //{	
   if (m_fontNameLength == 0) 
	   {
		   m_fontName = new gchar[1];
		   m_fontName[0]='\0';
	   }
   
   else 
	   {
		   gchar const *tempFontName = (gchar const *)gsf_input_read(input, sizeof(gchar)*m_fontNameLength, NULL);
		   m_fontName = new gchar[m_fontNameLength];

		   guint16 tempLength1=0;
		   int numTokens=0;
		   int lastTokenPosition=0;
		   for (guint16 i=0; i<m_fontNameLength; i++) 
			   {
				   if (tempFontName[i] == 0x20) {
					   m_fontName[tempLength1]=' ';
					   tempLength1++;
					   numTokens++;
					   lastTokenPosition=tempLength1;
				   }
				   else if (tempFontName[i] != 0x00) {
					   m_fontName[tempLength1]=tempFontName[i];
					   tempLength1++;
				   }
			   }
		   m_fontName[tempLength1]='\0';
		   // TODO/HACK: probably should create a proper static function for doing this
		   // consume the last token (by replacing the first char with a null-terminator) if its a weight signifier
		   // (NB: not all wp fonts are terminated by weight, just enough of them to make this annoying
		   for (int j=0; j<numFontWeightStrings; j++) 
			   {
				   if (!strcmp(fontWeightStrings[j], &m_fontName[lastTokenPosition])) 
					   {
						   if (lastTokenPosition > 0)
							   m_fontName[lastTokenPosition-1]='\0';
						   break;
					   }
			   }
	   }

   //
   
   //}
   //    else
   //      return gIE_IMPORTERROR;
   WPD_DEBUG_MSG(("WordPerfect: Read Font (primary family id: %i, family member id: %i, font type: %i, font source file type: %i font name length: %i, font name: %s)\n", (int) m_primaryFamilyId, (int) m_primaryFamilyMemberId, (int) m_fontType, (int) m_fontSourceFileType, (int) m_fontNameLength, m_fontName));

}


{'fraction_non_alphanumeric': 0.11600646725949879, 'fraction_numerical': 0.023039611964430072, 'mean_word_length': 4.088431876606684, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3728896', 'n_tokens_mistral': 3580, 'n_tokens_neox': 3218, 'n_words': 898}