CVS edit link for kharbat

Hi there,

I always wanted to use custom fonts for titles and headlines in my websites. I've been using an amazing javascript library called typeface. That allows me to embed custom fonts in my web pages.

http://typeface.neocracy.org/

I decide to integrate this library with Drupal where the user will have a function called tf() that extends the regular t() function. but it takes more parameters like font name, css styles or class, to display text in the desired font and format.

Users can create their custom fonts and add as many fonts as they want to the module.
http://typeface.neocracy.org/fonts.html

The module will take care of loading the needed javascript files. And allows the user to manage installed fonts.

Here are some examples for the final result:
http://typeface.neocracy.org/examples.html

I think such technology is really needed out there, and it's much better than using SIFR as it requires flash plugin to be installed on the browser. While typeface renders text in a way that the browser is more familiar with.

You can download my very first version of this module here:
http://dev.untitledlabs.com/typeface.tar.gz

I hope you find it useful.

Regards,
Ahmad Kharbat

Comments

avpaderno’s picture

typeface.js is not released under GPL Licence; in that case, you cannot host it in the CVS repository. The fact the file is available for download from a third-party site is a reason more to not include it in Drupal.org.

The code should use Drupal functions, whenever possible; the code should use file_scan_directory(), not scandir().

kharbat’s picture

Assigned: Unassigned » kharbat
Status: Postponed (maintainer needs more info) » Fixed
StatusFileSize
new252.28 KB

Yeah your right. I will include installation steps & instructions in the documentation.. i just attached all required files to the module for demonstration.

avpaderno’s picture

Status: Fixed » Active

There is still something to fix.

  • typeface_fonts() still uses scandir.
  • typeface_version() uses the variable $matches, but it's not a local variable, nor it's a global variable.
  • In code like if(! function_exists('tf')) { there is no need to put a space after the !.
  • In the module, comments declare some functions as custom hooks, but they are not technically hooks; to be hooks your module should contain code like module_invoke_all('fonts'), or module_invoke('fonts').Differently, they are simply functions.
  • There is a function name that doesn't start with the name of the module (tf()).

This report can be set as closed/fixed by the person who approves your CVS application.

AjK’s picture

Status: Active » Needs work
kharbat’s picture

Status: Needs work » Active
StatusFileSize
new252.09 KB

Regarding the last point, the function tf() extends function t() . it's easier to use and remember when it's short. I'm also checking for function definition to avoid any conflicts or errors. I changed the function tf() to typeface() for now..

is there any workaround to have the function tf() registered as a common function, other than my way ?

Thanks

AjK’s picture

Status: Active » Needs review
kharbat’s picture

StatusFileSize
new257.72 KB

Hi there,

Excuse me for my questions, i'm just new to the process. The status is needs review and it's assigned to me. Does it mean that i have to review my module again ? Anyway, i already did and i had to do another modification at line 124 in the module. Here are the files attached again.

avpaderno’s picture

Regarding the last point, the function tf() extends function t() . it's easier to use and remember when it's short. I'm also checking for function definition to avoid any conflicts or errors.

tf() doesn't actually extend t() but it uses the function to return its output; I think it's a nuance.
Function names are prefixed with the module name to avoid conflicts; there are cases where it's acceptable that the function doesn't follow this rule, but they are limited cases. In any case, when the function name doesn't contain the module name as prefix, the function name is not two characters long, and it doesn't start with the name of a Drupal function.

The status of the report says that the code needs review from you.

kharbat’s picture

Thank you for the explanation.. i will read more about those cases. I have reviewed my code and i think it's fine for a dev version . What's the next step ?

AjK’s picture

I'm using the "needs review" for applicants to inform us, the CVS admins, a review is needed. I'm using "needs work" for the CVS admins to tell the applicants that after a review the applicant needs to do work.

kharbat’s picture

Thanks AJK, i'll be waiting for the admins review then :)

AjK’s picture

Note, anyone can review. The CVS admins do review also but the status helps us admins track the process.

avpaderno’s picture

Assigned: kharbat » Unassigned
Status: Needs review » Needs work

I guess I forgot once again to change the status; I apology for this.

kharbat’s picture

Hi KiamLaLuno, may i know what exactly should i work on ?

kharbat’s picture

Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work
 	if(!function_exists('typeface')) {
		function typeface($string, $font, $class = NULL, $css = NULL, $translate = TRUE, $args = array(), $langcode = NULL) {
			$string = ($translate ? t($string, $args, $langcode) : $string);
			return theme('typeface', $string, $font, $class, $css);
		}
	}

There is no need to check if typeface() is already defined, as the only module that can use such function is yours. I don't think typeface() is a PHP function (correct me if i am wrong).

It would also be better to use an array for the last parameters, and change the code accordingly.

kharbat’s picture

Status: Needs work » Needs review
StatusFileSize
new257.75 KB

Oh yes your right.. i fixed those points.. Thanks :)

kharbat’s picture

StatusFileSize
new257.73 KB

Please ignore the previous attached module.. use this one instead

avpaderno’s picture

Status: Needs review » Needs work
function typeface_font_name($file) {
  $font_name = str_replace('.typeface.js', '', $file);
  $font_name = str_replace(array('-', '_', '.'), ' ', $font_name);
  $font_name = ucwords($font_name);
  return check_plain($font_name);
}

can be rewritten as

function typeface_font_name($file) {
  $replacements = array(
    '.typeface.js' => '',
    '-' => ' ',
    '_' => ' ',
    '.' => ' ',
  );
  return check_plain(ucwords(strtr($file, $replacements)));
}

Verify you replace all the tab indentations you used with two spaces indentation.

kharbat’s picture

Status: Needs work » Needs review
StatusFileSize
new114.33 KB

Hi there, i have updated my module.. but i still have to do some work with javascript to be released to ready to use.

By the way does anybody know what's the best method to send javascript objects to server in json format?

avpaderno’s picture

Status: Needs review » Needs work

I am not sure that passing JSON data to PHP (which doesn't handle that type of data natively) is the simple way to do what you are trying to do.
You need a third-party JavaScript library because JavaScript doesn't natively support JSON (it is able to transform JSON data in native data using eval(), but it doesn't have a function to transform native data in JSON). I would try with a different format.

I would add the license for the JSON library you are using as a comment before the code. As the library is few code lines, I don't think it is a problem if it is include in one of your files. I am not sure its license is compatible with GPL License.

kharbat’s picture

Status: Needs work » Needs review

Okay.. since it's a javascript issue.. is it possible to keep the module in dev version until i find a way to send data from javascript to server ?

by the way.. i left the license inside the code as comment for copyrights..

avpaderno’s picture

Effectively, the EULA is a license agreement; therefore, the license is reported.

Commercial Use. You may sell for profit and freely distribute scripts and/or compiled scripts that were created with the SOFTWARE PRODUCT.

Isn't this in contrast with the GPL License?

I am not changing the status of the issue, so other people can review it.

kharbat’s picture

StatusFileSize
new112.85 KB

Hi there, I created my own javascript function to solve this issue.. here is the module.. it's almost complete.

avpaderno’s picture

Status: Needs review » Needs work

There are still some places where the code doesn't use Drupal functions (it uses ucfirst(), and strtolower()).

After this, I think the code could be accepted.

EDIT: There is a page in the Drupal API documentation that lists all the Unicode functions made available from Drupal. Of those functions, only few are not of any use for normal cases; the others can be normally used (and they should) by any modules.

kharbat’s picture

Status: Needs work » Needs review
StatusFileSize
new112.94 KB

Thanks.. the page was very useful.

avpaderno’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

avpaderno’s picture

Component: Miscellaneous » new project application
Assigned: Unassigned » avpaderno
Issue summary: View changes
Status: Closed (fixed) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.