Code Duplication    Length = 119-119 lines in 2 locations

lib/FPDF/src/font/makefont/makefont.php 1 location

@@ 300-418 (lines=119) @@
297
* patch:    optional patch for encoding                                        *
298
* type:     font type if fontfile is empty                                     *
299
*******************************************************************************/
300
function MakeFont($fontfile, $afmfile, $enc='cp1252', $patch=array(), $type='TrueType')
301
{
302
	//Generate a font definition file
303
	if(get_magic_quotes_runtime())
304
		@set_magic_quotes_runtime(0);
305
	ini_set('auto_detect_line_endings','1');
306
	if($enc)
307
	{
308
		$map=ReadMap($enc);
309
		foreach($patch as $cc=>$gn)
310
			$map[$cc]=$gn;
311
	}
312
	else
313
		$map=array();
314
	if(!file_exists($afmfile))
315
		die('<b>Error:</b> AFM file not found: '.$afmfile);
316
	$fm=ReadAFM($afmfile,$map);
317
	if($enc)
318
		$diff=MakeFontEncoding($map);
319
	else
320
		$diff='';
321
	$fd=MakeFontDescriptor($fm,empty($map));
322
	//Find font type
323
	if($fontfile)
324
	{
325
		$ext=strtolower(substr($fontfile,-3));
326
		if($ext=='ttf')
327
			$type='TrueType';
328
		elseif($ext=='pfb')
329
			$type='Type1';
330
		else
331
			die('<b>Error:</b> unrecognized font file extension: '.$ext);
332
	}
333
	else
334
	{
335
		if($type!='TrueType' && $type!='Type1')
336
			die('<b>Error:</b> incorrect font type: '.$type);
337
	}
338
	//Start generation
339
	$s='<?php'."\n";
340
	$s.='$type=\''.$type."';\n";
341
	$s.='$name=\''.$fm['FontName']."';\n";
342
	$s.='$desc='.$fd.";\n";
343
	if(!isset($fm['UnderlinePosition']))
344
		$fm['UnderlinePosition']=-100;
345
	if(!isset($fm['UnderlineThickness']))
346
		$fm['UnderlineThickness']=50;
347
	$s.='$up='.$fm['UnderlinePosition'].";\n";
348
	$s.='$ut='.$fm['UnderlineThickness'].";\n";
349
	$w=MakeWidthArray($fm);
350
	$s.='$cw='.$w.";\n";
351
	$s.='$enc=\''.$enc."';\n";
352
	$s.='$diff=\''.$diff."';\n";
353
	$basename=substr(basename($afmfile),0,-4);
354
	if($fontfile)
355
	{
356
		//Embedded font
357
		if(!file_exists($fontfile))
358
			die('<b>Error:</b> font file not found: '.$fontfile);
359
		if($type=='TrueType')
360
			CheckTTF($fontfile);
361
		$f=fopen($fontfile,'rb');
362
		if(!$f)
363
			die('<b>Error:</b> Can\'t open '.$fontfile);
364
		$file=fread($f,filesize($fontfile));
365
		fclose($f);
366
		if($type=='Type1')
367
		{
368
			//Find first two sections and discard third one
369
			$header=(ord($file[0])==128);
370
			if($header)
371
			{
372
				//Strip first binary header
373
				$file=substr($file,6);
374
			}
375
			$pos=strpos($file,'eexec');
376
			if(!$pos)
377
				die('<b>Error:</b> font file does not seem to be valid Type1');
378
			$size1=$pos+6;
379
			if($header && ord($file[$size1])==128)
380
			{
381
				//Strip second binary header
382
				$file=substr($file,0,$size1).substr($file,$size1+6);
383
			}
384
			$pos=strpos($file,'00000000');
385
			if(!$pos)
386
				die('<b>Error:</b> font file does not seem to be valid Type1');
387
			$size2=$pos-$size1;
388
			$file=substr($file,0,$size1+$size2);
389
		}
390
		if(function_exists('gzcompress'))
391
		{
392
			$cmp=$basename.'.z';
393
			SaveToFile($cmp,gzcompress($file),'b');
394
			$s.='$file=\''.$cmp."';\n";
395
			echo 'Font file compressed ('.$cmp.')<br>';
396
		}
397
		else
398
		{
399
			$s.='$file=\''.basename($fontfile)."';\n";
400
			echo '<b>Notice:</b> font file could not be compressed (zlib extension not available)<br>';
401
		}
402
		if($type=='Type1')
403
		{
404
			$s.='$size1='.$size1.";\n";
405
			$s.='$size2='.$size2.";\n";
406
		}
407
		else
408
			$s.='$originalsize='.filesize($fontfile).";\n";
409
	}
410
	else
411
	{
412
		//Not embedded font
413
		$s.='$file='."'';\n";
414
	}
415
	$s.="?>\n";
416
	SaveToFile($basename.'.php',$s,'t');
417
	echo 'Font definition file generated ('.$basename.'.php'.')<br>';
418
}
419
?>
420

ufpdf/font/makefont/makefont.php 1 location

@@ 300-418 (lines=119) @@
297
* patch:    optional patch for encoding                                        *
298
* type:     font type if fontfile is empty                                     *
299
*******************************************************************************/
300
function MakeFont($fontfile, $afmfile, $enc='cp1252', $patch=array(), $type='TrueType')
301
{
302
	//Generate a font definition file
303
	if(get_magic_quotes_runtime())
304
		@set_magic_quotes_runtime(0);
305
	ini_set('auto_detect_line_endings','1');
306
	if($enc)
307
	{
308
		$map=ReadMap($enc);
309
		foreach($patch as $cc=>$gn)
310
			$map[$cc]=$gn;
311
	}
312
	else
313
		$map=array();
314
	if(!file_exists($afmfile))
315
		die('<b>Error:</b> AFM file not found: '.$afmfile);
316
	$fm=ReadAFM($afmfile,$map);
317
	if($enc)
318
		$diff=MakeFontEncoding($map);
319
	else
320
		$diff='';
321
	$fd=MakeFontDescriptor($fm,empty($map));
322
	//Find font type
323
	if($fontfile)
324
	{
325
		$ext=strtolower(substr($fontfile,-3));
326
		if($ext=='ttf')
327
			$type='TrueType';
328
		elseif($ext=='pfb')
329
			$type='Type1';
330
		else
331
			die('<b>Error:</b> unrecognized font file extension: '.$ext);
332
	}
333
	else
334
	{
335
		if($type!='TrueType' && $type!='Type1')
336
			die('<b>Error:</b> incorrect font type: '.$type);
337
	}
338
	//Start generation
339
	$s='<?php'."\n";
340
	$s.='$type=\''.$type."';\n";
341
	$s.='$name=\''.$fm['FontName']."';\n";
342
	$s.='$desc='.$fd.";\n";
343
	if(!isset($fm['UnderlinePosition']))
344
		$fm['UnderlinePosition']=-100;
345
	if(!isset($fm['UnderlineThickness']))
346
		$fm['UnderlineThickness']=50;
347
	$s.='$up='.$fm['UnderlinePosition'].";\n";
348
	$s.='$ut='.$fm['UnderlineThickness'].";\n";
349
	$w=MakeWidthArray($fm);
350
	$s.='$cw='.$w.";\n";
351
	$s.='$enc=\''.$enc."';\n";
352
	$s.='$diff=\''.$diff."';\n";
353
	$basename=substr(basename($afmfile),0,-4);
354
	if($fontfile)
355
	{
356
		//Embedded font
357
		if(!file_exists($fontfile))
358
			die('<b>Error:</b> font file not found: '.$fontfile);
359
		if($type=='TrueType')
360
			CheckTTF($fontfile);
361
		$f=fopen($fontfile,'rb');
362
		if(!$f)
363
			die('<b>Error:</b> Can\'t open '.$fontfile);
364
		$file=fread($f,filesize($fontfile));
365
		fclose($f);
366
		if($type=='Type1')
367
		{
368
			//Find first two sections and discard third one
369
			$header=(ord($file[0])==128);
370
			if($header)
371
			{
372
				//Strip first binary header
373
				$file=substr($file,6);
374
			}
375
			$pos=strpos($file,'eexec');
376
			if(!$pos)
377
				die('<b>Error:</b> font file does not seem to be valid Type1');
378
			$size1=$pos+6;
379
			if($header && ord($file[$size1])==128)
380
			{
381
				//Strip second binary header
382
				$file=substr($file,0,$size1).substr($file,$size1+6);
383
			}
384
			$pos=strpos($file,'00000000');
385
			if(!$pos)
386
				die('<b>Error:</b> font file does not seem to be valid Type1');
387
			$size2=$pos-$size1;
388
			$file=substr($file,0,$size1+$size2);
389
		}
390
		if(function_exists('gzcompress'))
391
		{
392
			$cmp=$basename.'.z';
393
			SaveToFile($cmp,gzcompress($file),'b');
394
			$s.='$file=\''.$cmp."';\n";
395
			echo 'Font file compressed ('.$cmp.')<br>';
396
		}
397
		else
398
		{
399
			$s.='$file=\''.basename($fontfile)."';\n";
400
			echo '<b>Notice:</b> font file could not be compressed (zlib extension not available)<br>';
401
		}
402
		if($type=='Type1')
403
		{
404
			$s.='$size1='.$size1.";\n";
405
			$s.='$size2='.$size2.";\n";
406
		}
407
		else
408
			$s.='$originalsize='.filesize($fontfile).";\n";
409
	}
410
	else
411
	{
412
		//Not embedded font
413
		$s.='$file='."'';\n";
414
	}
415
	$s.="?>\n";
416
	SaveToFile($basename.'.php',$s,'t');
417
	echo 'Font definition file generated ('.$basename.'.php'.')<br>';
418
}
419
?>
420