Question: Is it possible to know text dimensions in Matlab? 

For example, is it possible to know the following measures

![enter image description here](https://i.stack.imgur.com/XfVL4.gif)

**UPDATE**

I need no image processing. I know I can deduce the location of baseline of "g" letter with simple commonly used artificial intelligence :) This is not what I want. I want Matlab give me what it has, namely, the font metrics. If it can't then the answer is "Matlab can't".

**UPDATE 2**

Currently I am trying to do via Java interface like this

```
figure_h=figure;
axes_h = axes('Position', [0, 0, 1, 1], 'Units', 'pixels');

s='g';
x=200;
y=200;

fontName = 'Times New Roman';
fontSize = 48; % will be in points

text('String', s, 'Units', 'pixels', 'Position', [x y], 'FontName', fontName, 'FontUnits', 'points', 'FontSize', fontSize);

% make equivalent Java font
jFont=java.awt.Font(fontName,java.awt.Font.PLAIN,fontSize);

% accessing metrics object
jFrame = get(figure_h,'JavaFrame');
jCanvas = jFrame.getAxisComponent;
jGraphics=jCanvas.getGraphics;
jMetrics=jGraphics.getFontMetrics;

%rectangle('Position', [x, y, jMetrics.charWidth(s), jMetrics.getDescent]);

```

but getting null pointer exception at `getFontMetrics`.

Answer: 
Did you debug the response of the ajax call? Use the debug tools of chrome or Firebug for Firefox to debug the requests or use <http://www.charlesproxy.com/> to do so.

I'm pretty sure your json response is not correct and probably containing an error. Also the tutorial you've linked doesn't show the best way to deal with json in CakePHP, see [this page](http://book.cakephp.org/2.0/en/views/json-and-xml-views.html) of the manual. Debug your response and update your question with it.
Simple autocomplete code

cities.ctp code

```
<? echo $this->Html->css('jquery-ui');
   echo $this->Html->script('jquery-1.10.2');
   echo $this->Html->script('jquery-ui');
   echo $this->Html->css('style.css');
 ?>
 <script>
  $(function() {
    var availableTags = [<?=$cities?>];
    $( "#city_from" ).autocomplete({
      source: availableTags
    });
  });
  </script>

<?php echo $this->Form->input("city_from", array('required'=>'true',  'class'=>'form-control', 'id'=>'city_from', 'placeholder'=>'City or airport', 'label'=>'<span class="opensans size13">Flying from</span>'));?>

```

Controller code

```
       //Airport cities string section starts
        $this->loadModel('AirportCity');
        $cities=$this->AirportCity->find('list',array('fields'=>'AirportCity.city_name'));
        $strCities='"'.implode('","',$cities).'"';
        $this->set('cities',$strCities);
        //Airport cities string section ends

```

for more assistance refer <http://jqueryui.com/autocomplete/>