Last active
January 5, 2016 12:26
-
-
Save bennadel/eda36df510b61efc59f2 to your computer and use it in GitHub Desktop.
Testing Foreign And Unicode Character Rendering With The CFDocument Tag In ColdFusion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!--- | |
Since our test page has UTF-8 characters embedded within it, we have to tell | |
ColdFusion how to parse this page for proper character interpretation. | |
---> | |
<cfprocessingdirective pageEncoding="utf-8" /> | |
<cfparam name="url.fontName" type="string" /> | |
<cfoutput> | |
<!--- | |
Not all fonts can be used inside of the CFDocument tag. The attempt to use | |
certain fonts will result in a NullPointer exception. As such, we need to | |
wrap the usage in a try / catch so we can show a nicer message to the user. | |
---> | |
<cftry> | |
<cfdocument | |
format="pdf" | |
fontembed="true" | |
marginBottom="0" | |
marginLeft="0" | |
marginRight="0" | |
marginTop="0" | |
pageHeight="2"> | |
<p style="font-family: '#url.fontName#' ; font-size: 20px ;"> | |
<strong>#url.fontName#</strong>: | |
<!--- UNICODE CHARACTERS REMOVED - NOT SUPPORTED BY MY BLOG - PARTY FOUL :( ---> | |
</p> | |
</cfdocument> | |
<!--- Catch any failure to use the given font. ---> | |
<cfcatch> | |
<p style="font-family: '#url.fontName#' ; font-size: 20px ; color: ##CC0000 ;"> | |
<strong>#htmlEditFormat( url.fontName )#</strong>: | |
— | |
#htmlEditFormat( cfcatch.message )# | |
</p> | |
</cfcatch> | |
</cftry> | |
</cfoutput> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfscript> | |
// In order to get the fonts, we have to log into the CF Admin using the | |
// Administrator API. | |
adminGateway = createObject( "component", "cfide.adminapi.administrator" ); | |
adminGateway.login( "********************************" ); | |
runtimeGateway = createObject( "component", "cfide.adminapi.runtime" ); | |
// Grab the system fonts and the user fonts. | |
systemFonts = runtimeGateway.getFonts().systemFonts; | |
userFonts = runtimeGateway.getFonts().userFonts; | |
// The font list is a little confusing. Half of the fonts seem to completely | |
// error out for me. And, of those fonts, the vast majority of them seemed to | |
// be fonts that contained a "-". As such, this step merges the System Fonts | |
// and the User Fonts while, at the same time, stripping the "- suffix" from | |
// the font list. | |
// -- | |
// NOTE: I am using listFirst() for all fonts, regardless of whether or not | |
// there is a "-" present since the lack of "-" will just grab the entire | |
// font name as the "first item" in the list. | |
uniqueFonts = {}; | |
// Merge in the system fonts. | |
for ( fontName in systemFonts ) { | |
uniqueFonts[ listFirst( fontName, "-" ) ] = true; | |
} | |
// Merge in the user fonts. | |
for ( fontName in userFonts ) { | |
uniqueFonts[ listFirst( fontName, "-" ) ] = true; | |
} | |
// Now that we have a map of the font names, let's convert it to a sorted | |
// array for a slightly better user experience. | |
fontNames = structKeyArray( uniqueFonts ); | |
arraySort( fontNames, "textnocase" ); | |
</cfscript> | |
<cfcontent type="text/html; charset=utf-8" /> | |
<cfoutput> | |
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title> | |
ColdFusion CFDocument Font Testing | |
</title> | |
<style type="text/css"> | |
iframe { | |
border: 1px solid ##000000 ; | |
height: 50px ; | |
margin: 10px 0px 10px 0px ; | |
overflow: hidden ; | |
width: 100% ; | |
} | |
</style> | |
</head> | |
<body style="width: 875px ;"> | |
<h1> | |
ColdFusion CFDocument Font Testing | |
</h1> | |
<cfloop index="fontName" array="#fontNames#"> | |
<!--- | |
Render each font inside its own iframe. This way, if the CFDocument | |
tag can't handle the given font, and explodes, the damage is contained. | |
---> | |
<iframe | |
title="Font: #htmlEditFormat( fontName )#" | |
src="./document.cfm?fontName=#urlEncodedFormat( fontName )#"> | |
</iframe> | |
</cfloop> | |
</body> | |
</html> | |
</cfoutput> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment